JOIN and WHERE condiiton
-
hi, suppose i have 2 tables table1,table2 i wrote the following join query
SELECT * FROM table1 AS T1
JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
WHERE T1.idtable1 > 10My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?
My small attempt...
-
hi, suppose i have 2 tables table1,table2 i wrote the following join query
SELECT * FROM table1 AS T1
JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
WHERE T1.idtable1 > 10My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?
My small attempt...
-
hi, suppose i have 2 tables table1,table2 i wrote the following join query
SELECT * FROM table1 AS T1
JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
WHERE T1.idtable1 > 10My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?
My small attempt...
It is applied to the result of the join. In the past I have tried to "optimize" such statements as:
SELECT * FROM table1 AS T1
JOIN table2 AS T2
ON T1.idtable1 > 10
AND T1.idtable1 = T2.idtable1but saw no improvement.
-
hi, suppose i have 2 tables table1,table2 i wrote the following join query
SELECT * FROM table1 AS T1
JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
WHERE T1.idtable1 > 10My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?
My small attempt...
-
I think that depends on the database you are using. MS SQL would apply the where clause before the join. And you caan check this by getting the query-plan.
Wout Louwers
AFAIK SQL Server applies it before or after the join depending on what it thinks would give you the quickest result.