Whats the difference between using a LEFT OUTER JOIN, rather than a sub-query that starts with a WHERE NOT EXISTS (...)?
Whats the difference between using a LEFT OUTER JOIN , rather than a sub-query
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No they are not the same thing, as they will not return the same rowset in the most simplistic use case.
The
LEFT OUTER JOINwill return all rows from the left table, both where rows exist in the related table and where they does not. TheWHERE NOT EXISTS()subquery will only return rows where the relationship is not met.However, if you did a
LEFT OUTER JOINand looked forIS NULLon the foreign key column in theWHEREclause, you can make equivalent behavior to theWHERE NOT EXISTS.For example this:
Is equivalent to this:
But this one is not equivalent:
It will return rows from
t_mainboth having and not having related rows int_related.Note This does not speak to how the queries are compiled and executed, which differs as well — this only addresses a comparison of the rowsets they return.