What is the difference between WHERE and HAVING?

SQL SELECT, filtering and sorting · Freshers and experienced

Model answer

WHERE filters rows before grouping. HAVING filters groups after aggregation, so it can use aggregate functions: HAVING COUNT(*) > 5. Put conditions in WHERE whenever possible, since it reduces the data earlier.

Learn this topic

SELECT, FROM and WHERE: Your First Queries in the course SQL for Beginners: Learn Databases Step by Step.

Sign in to add your own answer.

More questions