Google News
logo
SQL Server - Interview Questions
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
The differences between HAVING CLAUSE and WHERE CLAUSE is :
 
* HAVING Clause : HAVING CLAUSE is used only with the SELECT statement. It is generally used in a GROUP BY clause in a query.
 
 If GROUP BY is not used, HAVING works like a WHERE clause. HAVING clause can be used with the aggregate function.
 
Syntax :
SELECT expr1, expr2, expr3..,  
FROM tables  
WHERE condition   
GROUP BY expr1, expr2, expr3..,  
HAVING condition;   

 

WHERE Clause : The WHERE clause is applied to each row before they become a part of the GROUP BY function in a query. 'WHERE' clause cannot use with the aggregate function.
 
Syntax :
WHERE condition;
Advertisement