Home > DeveloperSection > Interviews > What is the difference between a "where" clause and a "having" clause?

Posted on    October-25-2010 12:00 AM

 MSSQL Server MSSQL Server 
Ratings:
 1 Answer(s)
  1059  View(s)
Rate this:

Amit Singh

Total Post:565

Points:2825
Posted on    October-30-2010 12:00 AM

Difference between a Where Clause and a Having Clause

Having Clause is basically used only with the GROUP BY function in a query.
WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.

Syntax
Having Clause:

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value

Where Clause

SELECT column_name(s)
FROM table_name
WHERE column_name operator value



Don't want to miss updates? Please click the below button!

Follow MindStick