LEFT JOIN depending on more conditions

5 pts.
Tags:
ANSI norm
Database programming
JOIN statement
LEFT JOIN
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.
ASKED: October 13, 2008  8:01 AM
UPDATED: October 13, 2008  9:01 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

———————————————–

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following