What Is The Difference Between The HAVING And WHERE Clause in SQL ?
What Is The Difference Between the HAVING And WHERE Clause in SQL?
can anyone give some appropriate description with a small example?
Add comment
Answers (1)
Add AnswerExample
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.