SQL Server To Join or Not to Join? (Joining Vs Multi-select) [duplicate]

piv4azn7  于 2023-05-16  发布在  其他
关注(0)|答案(2)|浏览(194)

This question already has answers here:

Explicit vs implicit SQL joins (12 answers)
Closed 4 days ago.

Which of the below SQL queries is more performant, and why?

SELECT <columns>
FROM Dealer, DealerContact
WHERE Dealer.ID = DealerContact.DealerID

SELECT <columns>
FROM Dealer d
JOIN DealerContact dc on d.ID = dc.DealerID
z9smfwbn

z9smfwbn1#

As far as I know, it's basically the same. Because the DBMS transforms all queries to improve their speed. The execution of the result would be the same.

py49o6xq

py49o6xq2#

By default FROM Dealer, DealerContact will do a CROSS JOIN that is exponentialy performance consuming. When you don't need to do a CROSS JOIN , don't do it.

It will be better for both performance and code quality to use [INNER] JOIN in your case.

You could have a look at Microsoft documentation for further information.

相关问题