5 pts.
 LEFT JOIN depending on more conditions
I'm not sure what says the ansi norm about this SELECT * FROM a LEFT JOIN b ON b.mast_id = a.id AND b.flag = 1. Is it possible (by the ansi norm) to use in "ON" condition more then one boolean expression? Like in this case condition compounded by two expressions? Of course, meaning by this that left joined are only these records, which satisfy both condition. Or is the right interpretation that left joined are records that match first condition (b.mast_id = a.id) and then the result set is limited by the second condition (flag=1). Please let me know what You think about it. Thank You.

Software/Hardware used:
ASKED: October 13, 2008  8:01 AM
UPDATED: October 13, 2008  9:01 PM

Answer Wiki:
I think you can for sure use more than one condition to join the tables. In any case, if just one boolean expression was permitted, I think you should only need to place all conditions inside parenthesis, because at the end, all of them will evaluate to one single 'true' or 'false'. By definition, JOIN conditions are part of the FROM clause, not part of the WHERE clause, so the resultant join table will contain all records which satisfy both conditions, but since the second condition in your example is comparing a field from table b to a specific value, which has nothing to do with the other joined table, I think the result would be the same as if you put that condition in the where clause (although the execution plan could be different), and I would prefer the latter for better readability. -----------------------------------------------
Last Wiki Answer Submitted:  October 13, 2008  9:01 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _