I was wondering if there is any difference in the way SQL performs on these join statements:
SELECT * FROM a,b WHERE a.ID = b.ID
SELECT * FROM a JOIN b ON a
I despise when you force a join by using WHERE
. It just doesn't to me look right, a dirty hack. Proper ANSI join is to use ON:
SELECT
p.Product,
o.Order
FROM
Product p
INNER JOIN
Order o
ON
o.OrderID = p.OrderID
Prefer using ON
when joining and WHERE
to filter results. Remember WHERE is one of the last things you will use besides grouping and order by where you want to filter your results. So you shouldn't join your tables using WHERE
as it is much difficult to read.
SELECT
p.Product,
o.Order
FROM
Product p
INNER JOIN
Order o
ON
o.OrderID = p.OrderID
WHERE
o.Category = 'IT'
In the end you (the developer) might not be around in the future so readability and maintainability will help the pour soul who has to take over your code :).
When I see developers use WHERE
to join their tables it's usually an indication that they don't know enough T-SQL. That is my personal opinion.