MySQL Question: joining 4 tables...

Discussion in 'OT Technology' started by brds, Apr 18, 2008.

  1. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,645
    Likes Received:
    15
    Location:
    Atlanta
    I was wondering if anybody could provide me with a template for joining for tables. The most i could find was a two table join with a template of:


    Anybody able to help me out and show a template for 4 tables?

    Thanks!
     
  2. HardTech

    HardTech hungry

    Joined:
    May 5, 2000
    Messages:
    28,103
    Likes Received:
    1
    Location:
    NorCal
    it's the same format

    Code:
    SELECT field1, field2, field3
    FROM table1
    
    INNER JOIN table2
    on table1.key = table2.key
    
    INNER JOIN table3
    on table1.key = table3.key
    
    INNER JOIN table4
    on table1.key = table4.key
     
  3. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,645
    Likes Received:
    15
    Location:
    Atlanta
    Thanks.... helped me out with my assignment. Took me about 30 minutes to do what would have taken me a couple hours. :h5:
     
  4. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    1) Alias your tables in your joins, as it creates cleaner SQL.
    2) You need to join them all at once, one to the other? Do this:

     

Share This Page