Multiple Left Joins

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Multiple Left Joins

Post by Benjamin »

Please tell me if I am doing this query correctly. I am getting out of memory errors from MySQL ERROR: 28. I am selecting data based on criteria from a primary table which is large, and just obtaining misc data from the other small tables.

1. Does it matter what order I join them in? (ie is SmallTableOne.Record = LargeTable.Record the same as LargeTable.Record = SmallTableOne.Record?)
2. Is this the correct Join to use?

Code: Select all

FROM `LargeTable`
LEFT JOIN (
  `SmallTableOne` , `SmallTableTwo` , `SmallTableThree`
) ON (
  SmallTableOne.Record = LargeTable.Record
  AND SmallTableTwo.Record = LargeTable.Record
  AND SmallTableThree.Record = LargeTable.Record )
EDIT, I changed the join type from LEFT JOIN to JOIN and I no longer get the out of memory error. Comments still appreciated though.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

LEFT JOIN is useful when you still want the records from the table you're joining it to. When a match isn't found, all column references to that table will be NULL.
Post Reply