|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SELECT (left join)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. I think the where clause in the first query is not needed.
Have you compared the two execution plans? ML --- http://milambda.blogspot.com/ >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.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/ 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. |
|||||||||||||||||||||||