tags:

views:

73

answers:

2

Can anyone please tell me Which of the following queries will have better performance?

SELECT 
      * 
FROM 
      [TABLE1] T1 
      INNER JOIN [TABLE2] T2 
      ON T2.[FK_ID] = T1.[PK_ID] 
WHERE 
      T2.[ACTIVE] = 1; 

SELECT 
      * 
FROM 
      [TABLE1] T1 
      INNER JOIN [TABLE2] T2 
      ON T2.[FK_ID] = T1.[PK_ID] AND 
      T2.[ACTIVE] = 1; 
+3  A: 

They are identical: the optimizer is clever enough to work this out.

Not least, SQL is declarative so you're asking the optimizer for something but not telling it how to do it.

However, the first one is "correct" in that you are separating JOIN and WHERE.

gbn
+1 for difference between declarative versus... um apparently imperative according to Wikipedia.
Jesse Dhillon