I’m working on SQL Server 2008-R2 and I need to use multiple tables join. In that case, which query has better time performance, when using the WHERE statement or using INNER JOIN with ON statement ? both statements using the AND operator for multi conditions.
I would like to know if there is also some relevant query tuning for that issue.
Sample code for the options above:
1)
SELECT *
FROM T1,T2,T3....
WHERE T1.ID = T2.ID AND
T1.ID = T3.ID AND
....
2)
SELECT *
FROM T1
INNER JOIN T2
ON T1.ID = T2.ID
INNER JOIN T3
ON T1.ID = T3.ID
INNER JOIN .....
Tx.
Quick answer: No, there is no difference in performance.
This is a rather commonly asked question and is explained well here: INNER JOIN ON vs WHERE clause
The query optimization engine in SQL server will automatically convert both of these queries into the same approach for retrieving results.
The biggest difference in performance for your query would be the order of your joins and how much data was filtered with each new join. The most selective join statements (which filter out the most results) should come first (as much as possible depending on the tables you’re joining).