Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    106

    Limitare una sola tabella

    Salve a tutti
    nella query mysql ho unito due tabelle con inner join

    SELECT bx_spy_data.*, Profiles.ID, Profiles.Avatar, bx_photos_main.Owner, bx_photos_main.Title, bx_photos_main.Desc, bx_photos_main.Hash, bx_photos_main.Ext , bx_photos_main.ID

    FROM bx_spy_data

    INNER JOIN Profiles ON bx_spy_data.sender_id = Profiles.ID

    INNER JOIN bx_photos_main ON bx_spy_data.sender_id = bx_photos_main.Owner

    WHERE ( sender_id=$mioid OR recipient_id=$mioid
    or (sender_id IN (select friend_id from bx_spy_friends_data where sender_id=$mioid)) or (recipient_id IN
    (select friend_id from bx_spy_friends_data where sender_id=$mioid)))

    ORDER BY bx_spy_data.id DESC LIMIT 0,30

    il problema e che della tabella BX_PHOTOS_MAIN.ID vorrei visualizzare solo L'ULTIMO ID , delle altre va bene il limite 0,30 , ma di BX_PHOTOS_MAIN solo l'ultimo..


    sapete se è possibile ?

  2. #2
    Da ignorante di mysql, non si può mettere un'altra condizione nella where di questo tipo?

    SELECT bx_spy_data.*, Profiles.ID, Profiles.Avatar, bx_photos_main.Owner, bx_photos_main.Title, bx_photos_main.Desc, bx_photos_main.Hash, bx_photos_main.Ext , bx_photos_main.ID

    FROM bx_spy_data a, BX_PHOTOS_MAIN b

    INNER JOIN Profiles ON bx_spy_data.sender_id = Profiles.ID

    INNER JOIN bx_photos_main ON bx_spy_data.sender_id = bx_photos_main.Owner

    WHERE ( sender_id=$mioid OR recipient_id=$mioid
    or (sender_id IN (select friend_id from bx_spy_friends_data where sender_id=$mioid)) or (recipient_id IN
    (select friend_id from bx_spy_friends_data where sender_id=$mioid)))
    AND b.ID in (select max(ID) from BX_PHOTOS_MAIN)

    ORDER BY bx_spy_data.id DESC LIMIT 0,30
    "Na' sedia te vojo tirà!"

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    106
    ho sbagliato , il problema non è limitare la query o farmi restituire il primo valore !!

    scusatemi allora proverò a spiegarmi meglio

    riscrivo la query
    Codice PHP:
    SELECT bx_spy_data.*, Profiles.IDProfiles.Avatarbx_photos_main.Ownerbx_photos_main.Titlebx_photos_main.Descbx_photos_main.Hashbx_photos_main.Ext bx_photos_main.ID

    FROM bx_spy_data 

    INNER JOIN Profiles ON bx_spy_data
    .sender_id Profiles.ID 

    INNER JOIN bx_photos_main ON bx_spy_data
    .sender_id bx_photos_main.Owner 

    WHERE 
    sender_id=1274 OR recipient_id=1274 
    or (sender_id IN (select friend_id from bx_spy_friends_data where sender_id=1274)) or (recipient_id IN
    (select friend_id from bx_spy_friends_data where sender_id=1274))) 

    ORDER BY bx_spy_data.id DESC LIMIT 0,30 
    so per certo che tutte le condizioni qui sopra elencate si verificano sempre , però potrebbe accadere che tutte le tabelle sviluppino dati eccetto bx_photos_main che qualche volta potrebbe essere vuota

    attualmente a me interessa che prende SEMPRE i dati dalle tabelle ANCHE SE bx_photos_main è VUOTA .. invece no non fa cosi , per svilupparmi dati lui mysql controlla che

    bx_spy_data - bx_photos_main - Profiles

    abbiano tutti l'id 1274 (cioè la condizione)

    invece io vorrei qualcosa che sviluppa dati in ogni caso , quindi risultati

    se bx_photos_main è vuota , non c'è corrispondenza , cmq mi va vedere lo stesso i risultati di


    bx_spy_data - Profiles

    spero di essermi spiegato



  4. #4
    Se penso di aver capito il tuo problema puoi provare con l'OUTER JOIN piuttosto che con l'INNER, per la tabella che potrebbe non avere dati di corrispondenza. :master:
    "Na' sedia te vojo tirà!"

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    106
    Codice PHP:
    SELECT bx_spy_data.*, Profiles.IDProfiles.Avatarbx_photos_main.Ownerbx_photos_main.Titlebx_photos_main.Descbx_photos_main.Hashbx_photos_main.Ext bx_photos_main.ID

    FROM bx_spy_data

    INNER JOIN Profiles ON bx_spy_data
    .sender_id Profiles.ID
    OUTER JOIN bx_photos_main ON bx_spy_data
    .sender_id bx_photos_main.Owner

    WHERE 
    sender_id=1274 OR recipient_id=1274
    or (sender_id IN (select friend_id from bx_spy_friends_data where sender_id=1274)) or (recipient_id IN
    (select friend_id from bx_spy_friends_data where sender_id=1274)))

    ORDER BY bx_spy_data.id DESC LIMIT 0,30 

    ERRORE : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OUTER JOIN bx_photos_main ON bx_spy_data.sender_id = bx_photos_main.Owner WHE' at line 6

    NIENTE

  6. #6
    Ti ripeto, non sono esperto di mysql, ma leggendo su internet credo che si scriva così:

    SELECT bx_spy_data.*, Profiles.ID, Profiles.Avatar, bx_photos_main.Owner, bx_photos_main.Title, bx_photos_main.Desc, bx_photos_main.Hash, bx_photos_main.Ext , bx_photos_main.ID

    FROM bx_spy_data

    INNER JOIN Profiles ON bx_spy_data.sender_id = Profiles.ID
    LEFT OUTER JOIN bx_photos_main ON bx_spy_data.sender_id = bx_photos_main.Owner

    WHERE ( sender_id=1274 OR recipient_id=1274
    or (sender_id IN (select friend_id from bx_spy_friends_data where sender_id=1274)) or (recipient_id IN
    (select friend_id from bx_spy_friends_data where sender_id=1274)))

    ORDER BY bx_spy_data.id DESC LIMIT 0,30
    "Na' sedia te vojo tirà!"

  7. #7
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    106
    niente ...

  8. #8
    Se togli outer e lasci left?
    "Na' sedia te vojo tirà!"

  9. #9
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    106
    niente , finchè non c'è nessun valore in bx_photos_main mi da valore NULL è va benissimo , appena però c'è qualche valore in bx_photos_main , quel valore viene duplicato in tutti i record

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.