Home All Groups Group Topic Archive Search About
Author
9 Dec 2005 8:23 AM
Petar Popara
Is there any difference between this:

SELECT a.Something FROM table1 a
LEFT JOIN table2 b ON a.ID_Account = b.ID_Account AND a.ID_Contract =
b.ID_Contract
WHERE a.ID_Contract = b.ID_Contract

and

SELECT a.Something FROM table1 a
LEFT JOIN table2 b ON a.ID_Account = b.ID_Account
WHERE a.ID_Contract = b.ID_Contract

?

Thank you in advance.

Author
9 Dec 2005 8:49 AM
ML
I think the where clause in the first query is not needed.
Have you compared the two execution plans?


ML

---
http://milambda.blogspot.com/
Author
9 Dec 2005 11:04 AM
Petar Popara
>I think the where clause in the first query is not needed.
I think it is needed.

> Have you compared the two execution plans?
As much as I can see, results for both quesries are the same.
Author
9 Dec 2005 12:22 PM
ML
In your first query one condition is both in the join and in the where
clause. Try removing it from the where clause, that might affect the
execution plan.

Of course you should free the cache between individual tests.


ML

---
http://milambda.blogspot.com/
Author
9 Dec 2005 2:44 PM
Alexander Kuznetsov
Petar,
the queries are identical:
because of the condition WHERE a.ID_Contract = b.ID_Contract (which
means that b.ID_Contract is not null), your left OUTER join essentially
becomes an INNER one. In most cases the optimizer recognizes that no
problem. Try removing LEFT keyword altogether and see if it affects the
execution plan, most probably it will not.

AddThis Social Bookmark Button