Archive

Posts Tagged ‘Performance tuning’

Which SQL statement is faster? (EXISTS or IN …)

December 9, 2014 Leave a comment

Based on Question asked in MSDN Forum

  1.  IN is efficient when most of the filter criteria is in the sub-query.
  2.  EXISTS is efficient when most of the filter criteria is in the main query.
  3.  Usually IN has the slowest performance.

For more you can refer Join vs Exists vs In (SQL)IN vs. JOIN vs. EXISTS

Advertisements
Categories: SQL Tags: , ,

Which SQL statement is faster? (HAVING vs. WHERE…)

December 9, 2014 Leave a comment

If a condition refers to an aggregate function, put that condition in the HAVING clause. Otherwise, use the WHERE clause.

You can use HAVING but recommended you should use with GROUP BY.

SQL Standard says that WHERE restricts the result set before returning rows and HAVING restricts the result set after bringing all the rows. So WHERE is faster.

Categories: SQL Tags: , ,
%d bloggers like this: