Thursday, August 12, 2010

Difference between a WHERE clause and HAVING clause?

  • WHERE clause used to filter the physical rows in your table(s) whereas the HAVING clause operates on groups of a result-set (usually aggregate) and specifies which of the summary rows are returned in your resultset.  
  • A WHERE clause is independent of GROUP BY clause but the HAVING clause does depend on this, although it can be used without this as well.
  •  First SQL Server filters the physical rows using WHERE conditions and then performs GROUP BY on filtered data in memory and then filters the aggregated rows again with HAVING clause.

Example:
List of all the employee with basic greater than 3000.

Now I want to calculate the Dept codes for which total of basic is greater than 20,000 for those employees who are getting basic more than 3000.

as

No comments:

Post a Comment