SQL HAVING Clause
Exhibit
Refer to the exhibit. ```sql SELECT ProductID, SUM(Quantity) AS TotalQuantity FROM Sales WHERE OrderDate >= '2023-01-01' GROUP BY ProductID HAVING SUM(Quantity) > 100 ORDER BY TotalQuantity DESC; ```
The exhibit shows a SQL query run against Azure SQL Database. What is the purpose of the HAVING clause in this query?
Quick Answer
The correct answer is that the HAVING clause filters groups after GROUP BY based on aggregate conditions. This is because SQL processes WHERE before grouping, so WHERE cannot evaluate aggregate functions like SUM or COUNT—those values only exist after rows are grouped. HAVING steps in precisely at that point, allowing you to restrict groups by their aggregated results, such as only showing departments with a total salary over $100,000. On the Microsoft Azure Data Fundamentals DP-900 exam, this concept often appears in a query exhibit where a WHERE clause is mistakenly used with an aggregate, testing your understanding of SQL execution order. A common trap is confusing HAVING with WHERE; remember that WHERE filters rows, HAVING filters groups. For a quick memory tip, think “WHERE works on rows, HAVING works on groups—HAVING comes after GROUP BY.”
⚠ Common exam trap
Many candidates confuse HAVING with WHERE, mistakenly thinking HAVING can filter individual rows before grouping, when in fact WHERE must be used for that purpose.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
To filter groups based on aggregate conditions
The HAVING clause in SQL is used to filter groups after the GROUP BY clause has been applied, based on aggregate conditions such as SUM, COUNT, or AVG. In this query against Azure SQL Database, HAVING restricts the result to only those groups that satisfy the specified aggregate condition, which cannot be done with a WHERE clause because WHERE filters individual rows before grouping.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
To filter rows before grouping
Why it's wrong here
That's the WHERE clause.
- ✗
To sort the result set
Why it's wrong here
Sorting is done by ORDER BY.
- ✗
To join two tables
Why it's wrong here
Joins use JOIN clause.
- ✓
To filter groups based on aggregate conditions
Why this is correct
HAVING filters groups after GROUP BY using aggregate functions.
Go deeper
Related to this question
About these practice questions
One of 820 original DP-900 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on DP-900
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. The exhibit shows a T-SQL query against an Azure SQL Database. What is the purpose of the HAVING clause in this query?
medium- A.To sort the result set by TotalSales descending
- B.To join two tables
- ✓ C.To filter groups after aggregation
- D.To filter rows before grouping
Why C: The HAVING clause is used in T-SQL to filter groups after the GROUP BY clause has performed aggregation. In this query, it restricts the result set to only those product categories whose total sales (SUM(Amount)) exceed 1000, which is a condition on the aggregated value, not on individual rows.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DP-900 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DP-900 exam.