Page 1 of 1

Multiple Left Joins

Posted: Wed Mar 22, 2006 7:56 am
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.

Posted: Wed Mar 22, 2006 8:50 am
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.