Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Left joining more than 3 tables 1

Status
Not open for further replies.

aalnaif

Technical User
Jan 12, 2007
44
CA
Is there an easy way to join more than 3 tables in MySQL without resorting to the nested Left join? I'm trying to join ~ 20 tables and the syntax I'm thinking about using is:

SELECT a.Col1, b.Col2, c.Col3, d.Col4
FROM Tbl1 AS a
LEFT JOIN Tbl2 AS b
ON a.Col1 = b.Col2
LEFT JOIN Tbl3 AS c
ON a.Col1 = c.Col3
LEFT JOIN Tbl4 AD d
ON a.Col1 = d.Col4;

My only stipulation is that even if the tables b, c, d don't have rows that are in a, they get set to null (I'm under the impression this is cool with the left join setting A to the master). Is there a better way, or is this the best way?

Thanks in advance.
 
Okay, thanks.

I'm just hoping now this carries for ~20 joins.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top