So this should be a simple, elementary, question, that I should know like the back of my hand. I've been assuming one thing or else learned it early on, but now find myself wondering, does it even matter at all.
So If I have 2 tables, #Table1 and Table2, and I want to do a LEFT Join where I look for all records in table1 and only records from table2 that match table1, does it matter if I put the T1_ID on the left or right in the ON portion of the JOIN statement?
So consider:
So when I tested this on a production server, I got the same count either way I ran it. So, does this tell me that the location in the ON Clause does not matter, even if I use a LEFT JOIN? Does it only matter where I have the table/view/object name in the FROM Clause? It seems to be that way, but I wanted to verify.
Historically, I've always thought you should put the first table/object in the JOIN first, so T1_ID = T2_ID, and not the other way around. But perhaps that's just good form, but not required.
Can anyone shed any light on this? Sorry for this basic, low level question.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
So If I have 2 tables, #Table1 and Table2, and I want to do a LEFT Join where I look for all records in table1 and only records from table2 that match table1, does it matter if I put the T1_ID on the left or right in the ON portion of the JOIN statement?
So consider:
Code:
SELECT COUNT(1)
FROM Table1 a WITH (NOLOCK)
LEFT JOIN Table2 ci WITH (NOLOCK) ON ci.AcctID = a.AcctID
SELECT COUNT(1)
FROM Table1 a WITH (NOLOCK)
LEFT JOIN Table2 ci WITH (NOLOCK) ON a.AcctID = ci.AcctID
So when I tested this on a production server, I got the same count either way I ran it. So, does this tell me that the location in the ON Clause does not matter, even if I use a LEFT JOIN? Does it only matter where I have the table/view/object name in the FROM Clause? It seems to be that way, but I wanted to verify.
Historically, I've always thought you should put the first table/object in the JOIN first, so T1_ID = T2_ID, and not the other way around. But perhaps that's just good form, but not required.
Can anyone shed any light on this? Sorry for this basic, low level question.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57