What Is The Difference Between The HAVING And WHERE Clause in SQL ?

Forums SQLWhat Is The Difference Between The HAVING And WHERE Clause in SQL ?
Staff asked 1 month ago

What Is The Difference Between the HAVING And WHERE Clause in SQL?

can anyone give some appropriate description with a small example?

Answers (1)

Add Answer
Shaikh Hafeezjaha Marked As Accepted
Staff answered 1 month ago

Example

Let us consider the above table #TempTable

//Where clause
SELECT name, age FROM #TempTable 
WHERE age >=25
//Having clause
SELECT age, COUNT(Id) AS Total_Count 
FROM #TempTable  GROUP BY age
HAVING COUNT(Id) > 1

WHERE

  • It is used to perform filtration on individual rows.
  • It can be used with SELECT, UPDATE, and DELETE statements.
  • WHERE clause used before GROUP BY clause.

HAVING

  • It is used to perform filtration on groups.
  • It can only be used with SELECT statements.
  • HAVING clause used after GROUP BY clause.

 

 

Subscribe

Select Categories