Please go through the following query, and help me to understand which one is efficient and how?
In logical query execution, where clause will be executed after completion of join, so I thought the query 2 will gain the performance benefits. Is that right?
Query 1:
select a.*, b.* from table1 a join table2 b on a.colA = b.colA where a.ColB = 'Somevalue'
Query 2:
select a.*, b.* from (select * from table1 where ColB = 'Somevalue' ) a join table2 b on a.colA = b.colA
Thanks in advance
Advertisement
Answer
select a.*, b.* from table1 a join table2 b on a.colA = b.colA and a.ColB = 'Somevalue'