When joining two tables, what are the difference between the two blocks below and which is the better approach?
Pattern A:
SELECT ...
FROM A
INNER JOIN B
ON A.PK = B.FK
WHERE 1=1
AND A.Name = "Foo"
AND B.Title = "Bar"
Pattern B:
SELECT ...
FROM A
INNER JOIN B
ON A.PK = B.FK
AND B.Title = "Bar"
WHERE 1=1
AND A.Name = "Foo"
This is going to differ from person to person, but I think that Pattern A is better.
What it does is it separates the table level joins from the filters. This could be helpful for queries with multiple joins and multiple filters because it clearly separates the two types of joining that is going on.
I prefer pattern A, but there is probably not any difference. You really have to look at the execution plan though to make sure it is running efficiently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With