Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Join fra tre tabelle

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2001
    Messaggi
    231

    Join fra tre tabelle

    Ciao a tutti,
    ho un problema che non riesco a risolvere con PHP e MySql, ovvero il collegamento di tre tabelle di un database.

    Le tabelle sono:

    - gallery
    - category_gallery
    - sottocategory_gallery

    Struttura gallery "Sintetizzata":

    - id
    - foto
    - id_cat
    - id_sot

    Struttura category_gallery

    - id_cat
    - nomecat

    Struttura sottocategory_gallery

    - id_sot
    - nomesot

    Ho eseguito tre query diverse, ma mi da sempre errore:

    1) SELECT * FROM ((gallery INNER JOIN category_gallery ON gallery.id_cat = category_gallery.id_cat) INNER JOIN sottocategory_gallery ON gallery.id_sot = sottocategory.id_sot)

    2) SELECT * FROM (gallery INNER JOIN category_gallery ON gallery.id_cat = category_gallery.id_cat INNER JOIN sottocategory_gallery ON gallery.id_sot = sottocategory.id_sot)

    3) SELECT * FROM gallery JOIN category_gallery ON gallery.id_cat = category_gallery.id_cat AND gallery.id_sot = sottocategory_gallery.id_sot

    Se collego due tabelle invece funziona perfettamente:

    SELECT * FROM gallery INNER JOIN category_gallery ON gallery.id_cat = category_gallery.id_cat

    Dove può essere l'errore? Ho sempre collegato più tabelle tra di loro utilizzando la prima sintassi, con database ACCESS e non ho mai avuto problemi.. Forse MySql ha un'altra sintassi?

    Grazie a tutti, Max
    http://www.mdlwork.com

  2. #2

    Re: Join fra tre tabelle

    Originariamente inviato da masdel1979
    2) SELECT * FROM (gallery INNER JOIN category_gallery ON gallery.id_cat = category_gallery.id_cat INNER JOIN sottocategory_gallery ON gallery.id_sot = sottocategory.id_sot)
    questa sembra giusta.. ma le parentesi? :master:

    provato senza?

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2001
    Messaggi
    231

    fatto...

    In realtà andava scritta così:

    SELECT * FROM (gallery INNER JOIN category_gallery ON gallery.id_cat = category_gallery.id_cat) INNER JOIN sottocategory_gallery ON gallery.id_sot = sottocategory.id_sot

    Avevo sbagliato prima...

    Cmq ho provato anche senza parentesi... Che può essere??

    Non trovo soluzione...

    Saluti MAX
    http://www.mdlwork.com

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2001
    Messaggi
    231

    Questa funziona...

    Mi ero perso qualche pezzo

    SELECT * FROM gallery INNER JOIN sottocategory_gallery ON gallery.id_cat = sottocategory_gallery.id_cat INNER JOIN category_gallery ON category_gallery.id_cat = gallery.id_cat

    Grazie Comunque, MAX
    http://www.mdlwork.com

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 © 2025 vBulletin Solutions, Inc. All rights reserved.