views:

64

answers:

3

Which one is better using condition in where statement or in join statement? Can anyone please help?

+1  A: 

Here's a good reference:

http://msdn.microsoft.com/en-us/library/aa933232%28SQL.80%29.aspx

naikus
A: 

If the requirement to to filter the rows by a known set of fixed values then where x in (a, b, c, ...) will work better than where x like 'g' because it may not be possible to create a suitable like clause.

If the requirement is to filter by a prefix then where x like 'prefix%' will work better than where x in (a, b, c, ...) because it might not be possible to create an in() clause that is correct.

Janek Bogucki
+1  A: 

Any condition that prevents the a SQL server optimizer to use an index it's bad condition.

If in your case in or like operator is better that says the query plan only.

Typically a "%" wildcard at the beginning of the string prevents the SQL Server to use an index. Sometimes a in operator prevents to use an index.

BeachBlocker