Hello, Everyone.
I am using SQL Server 2008.
I am reviewing code from a previous developer and I do not understand something I am seeing. I get the concept but the specifics of how it works are escaping me. I was trained to use JOIN to join tables, not list tables and force comparison in a where clause.
The tables don't appear to be in the right order. How is the compiler sorting this out?
table1 and table2 are listed first and aren't even being tied together. Is it doing a cross-product first and then narrowing by table3 conditions? Seems a horrible waste of resources.
Why would someone do this?
Is there an advantage doing it this way?
Is is good/bad form?
I would right thus:
but since I don't understand the first one, I am not convinced 100% that it would be doing the same thing.
Thought?
Thanks all.
Patrick
I am using SQL Server 2008.
I am reviewing code from a previous developer and I do not understand something I am seeing. I get the concept but the specifics of how it works are escaping me. I was trained to use JOIN to join tables, not list tables and force comparison in a where clause.
Code:
SELECT myFieldList
FROM table1 t1, table2 t2, table3 t3
WHERE t3.Foreign_Key_1 = t1.Primary_Key_1
AND t3.Foreign_Key_2 = t2.Primary_Key_2
The tables don't appear to be in the right order. How is the compiler sorting this out?
table1 and table2 are listed first and aren't even being tied together. Is it doing a cross-product first and then narrowing by table3 conditions? Seems a horrible waste of resources.
Why would someone do this?
Is there an advantage doing it this way?
Is is good/bad form?
I would right thus:
Code:
SELECT myFieldList
FROM table3 AS t3
JOIN table1 AS t1
ON t3.Foreign_Key1=t1.Primary_Key1
JOIN table2 AS t2
ON t3.Foreign_Key2 = t2.Primary_Key2
but since I don't understand the first one, I am not convinced 100% that it would be doing the same thing.
Thought?
Thanks all.
Patrick