MySQL syntax for 7 tables joined

Discussion in 'PHP' started by Ronaldo30, Dec 9, 2005.

  1. #1
    Which is the SELECT command to display all fields in the joined tables, first table beeing "mistakes_xml"
    This is the link with tables image and the join between them.

    http://www.geocities.com/adr_pers/index.html[/URL]

    Which is the SELECT command to display fields:

    tags_init.name
    mistakes_init.name
    charge.name
    id_user.name for id_user_gener
    id_user.name for id_user_verif

    Thanks!

    Thanks!
     
    Ronaldo30, Dec 9, 2005 IP
  2. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Disclaimer: I haven't tested this. And I can't make out the picture very well, so I'm guessing at the field names.

    Heres the basic idea:

    select table1.field, table2.field ... from table1 left join table2 on table1.key = table2.index left join table3 on table2.key = table3.index ... where ...

    I probably don't have the syntax exactly right (missing, or maybe extra, commas, etc). But that's the general idea you want.

    It's going to be something along the lines of:

    select mistakes_xml.document, mistakes_xml.data, tags_init.whatever, generators.rr_doc_gener, generators.data, mistakes_init.rance, guest.name, guest.status, verified.name, verified.status, charge.tip_charge from mistakes_xml left join tags_init on mistakes_xml.id_tag = tags_init.id_tag, left join generators on mistakes_xml.id_generator = generators.id_generator, left join mistake_init on mistakes_xml.id_mistake = mistake_init.id_mistake, left join charge on generators.id_charge = charge.id_charge, left join users as guest on generators.id_user_guest = guest.id_user, left join users as verified on generators.id_user_verif = verified.id_user where ...

    Notice the parts I italicized. I'm starting to blur from exhaustion, so I probably have that wrong, too. But that's the basic gist of things.

    BTW, just a stupid nit-picky thing. It's considered "more normalized" for your tables to have plural names. So "charge" should probably be named "charges." I'm not sure I agree with this dogma, but that's the way it is.

    Good luck
     
    jimrthy, Dec 9, 2005 IP
  3. Ronaldo30

    Ronaldo30 Peon

    Messages:
    36
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Which is the SELECT command to display fields:

    tags_init.name
    mistakes_init.name
    charge.name
    id_user.name for id_user_gener
    id_user.name for id_user_verif
     
    Ronaldo30, Dec 9, 2005 IP