Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone explain the difference between where and having in SQL?

1 Answer

0 votes
by (119k points)

The difference between Where and Having clauses can be better explained when used along with Group by. Where clause is used to filter the rows before grouping and Having is used to filter the rows after grouping. This is the main difference between the where and having clauses.

In Where clause, we cannot use aggregate functions (AVG, MAX, MIN, SUM, and COUNT) but we can use aggregate functions in Having clauses. We can use where clause in SELECT, UPDATE, and DELETE statements but Having can be used only with Group by clause.

Here is the syntax to use Where and Having clauses in the same query:

SELECT columns_list
FROM TableName
WHERE condition(s)
GROUP BY columns_list
HAVING condition
ORDER BY columns_list;

You can check out this SQL interview questions blog by Intellipaat for more FAQs in the SQL interview with a better explanation.

Related questions

0 votes
1 answer
asked Oct 20, 2020 in SQL by dev_sk2311 (45k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 10, 2020 in SQL by dev_sk2311 (45k points)

Browse Categories

...