0

I have a problem with the where condtions and inner join conditions.

They are:

ex:

select * from table1 T

inner join table2 F on F.tkey=T.tkey and F.date >= '20140104'

and

select * from table1 T

inner join table2 F on F.tkey=T.tkey

where F.date >= '20140104'

**here which will be execute faster and why ?

SEB BINFIELD
  • 410
  • 3
  • 12

1 Answers1

1

The sequence of execution of any SQL query is :

FROM ->ON ->JOIN -> WHERE -> GROUP BY ->WITH CUBE or WITH ROLLUP->HAVING->SELECT->DISTINCT->ORDER BY ->TOP

so first one will execute faster because it will filter rows on the basis of given criteria while joining itself, where as the second query will join the tables first and then go for filtering rows

ankit
  • 1,499
  • 5
  • 29
  • 46
  • That's not necessarily true - depending on what SQL Parser he is using and how the parser analyzes the statement he could have different results. In many cases, his query above is simple enough that it might pick the same execution plan for both queries. –  Aug 13 '14 at 16:29