Hi
What's the difference between having the condition in FROM vs WHERE.
Alt 1:
SELECT t1.Title
FROM Table1 t1 INNER JOIN
Table2 t2 ON t1.Id = t2.Table1Id
WHERE t1.Active = 1
Alt 2:
SELECT t1.Title
FROM Table1 t1 INNER JOIN
Table2 t2 ON t1.Id = t2.Table1Id AND t1.Active = 1
Thanks.Senna wrote:
> Hi
> What's the difference between having the condition in FROM vs WHERE.
> Alt 1:
> SELECT t1.Title
> FROM Table1 t1 INNER JOIN
> Table2 t2 ON t1.Id = t2.Table1Id
> WHERE t1.Active = 1
>
> Alt 2:
> SELECT t1.Title
> FROM Table1 t1 INNER JOIN
> Table2 t2 ON t1.Id = t2.Table1Id AND t1.Active = 1
> Thanks.
In your examples there is no difference.
In the case of an OUTER join it does make a difference because the join
condition is evaluated first (logically speaking) and then the WHERE
clause is applied to the result.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks David, thats a good thing to know.
"David Portas" wrote:
> Senna wrote:
> In your examples there is no difference.
> In the case of an OUTER join it does make a difference because the join
> condition is evaluated first (logically speaking) and then the WHERE
> clause is applied to the result.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
No comments:
Post a Comment