#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2007
    Posts
    85
    Rep Power
    7

    MySQL JOIN 3 different tables


    How to join those 4 different tables so I can get string result instead of numbers. This is my query so far
    Code:
    SELECT mg_golub.ID AS IDgolub, mg_golub.brojgoluba, mg_golub.spol,
          mg_golub.boja, mg_golub.rasa, mg_golub.ime, mg_golub.godina,
          mg_drzava.drzava, mg_status.status
    FROM mg_golub
    JOIN mg_drzava  ON (mg_drzava.ID=mg_golub.IDdrzava)
    JOIN mg_status  ON (mg_status.ID=mg_golub.IDstatus)
    LEFT JOIN mg_popis_golubova AS Otac  ON (Otac.IDotac=mg_golub.ID)
    LEFT JOIN mg_popis_golubova AS Majka  ON (Majka.IDmajka=mg_golub.ID)
    JOIN mg_popis_golubova  ON (mg_golub.ID=mg_popis_golubova.IDgolub)
    WHERE mg_popis_golubova.IDkorisnik='$ID_KORISNIK'
    I don't know how to link those 3 fields from mg_popis_golubova to mg_golub. I'm stuck with, cause I can't pick data for those 2 columns.
    Code:
    LEFT JOIN mg_popis_golubova AS Otac ON (Otac.IDotac=mg_golub.ID)
    LEFT JOIN mg_popis_golubova AS Majka ON (Majka.IDmajka=mg_golub.ID)
    Last edited by dada1; May 23rd, 2013 at 12:04 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    90
    Rep Power
    3
    it's not exactly clear why you are joining mg_popus_golubova to mg_golub 3 times with 2 different kinds of JOINs. You appear to only be using the last JOIN.

    is this like saying
    where (mg_golub.ID=mg_popis_golubova.IDgolub or mg_golub.ID=mg_popis_golubova.IDmajka or mg_golub.ID=mg_popis_golubova.IDotac)
    ?

    Also, could you please give some sample of your ideal output?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2007
    Posts
    85
    Rep Power
    7
    I managed to fix this. but thank you

IMN logo majestic logo threadwatch logo seochat tools logo