HAVING CLAUSE:-
- The HAVING Clause was used in SQL because the WHERE keyword could not be used with aggregate functions.
- HAVING Clause used in only the SELECT query.
- HAVING Clause is used to filter values from a group.
- HAVING Clause is used to check conditions after the aggregation takes place.
- HAVING Clause used after the GROUP BY Clause.
WHERE CLAUSE:-
- WHERE Clause used in any SELECT query. WHERE clause with UPDATE and DELETE clause.
- WHERE Clause is used to filter rows.
- WHERE Clause is used to check conditions before the aggregation takes place.
- WHERE Clause is used before the GROUP BY Clause.
EXAMPLE:-
I have created two tables that are department and employee. And apply foreign key relationships on those tables.
In the below query selected those records whose salary is greater and equal to 20000.
In the below query selected those records whose id count not equal to 1.
If you are a newbie to database learning — SQL Server recommended is the following must-watch video: -