DA0-002 Data Acquisition and Preparation Practice Question
Exhibit
Refer to the exhibit. ``` SELECT customer_id, COUNT(order_id) AS order_count FROM orders GROUP BY customer_id HAVING COUNT(order_id) > 5 ORDER BY order_count DESC; ```
What is the primary purpose of the HAVING clause in the query shown?
⚠ Common exam trap
Watch out — candidates often confuse WHERE and HAVING: candidates often pick 'Filter rows before grouping' because they think all filtering happens before aggregation, but HAVING specifically filters groups after aggregation, not individual rows.
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
✓
Filter groups after aggregation
The HAVING clause is used to filter groups after the GROUP BY clause has aggregated the data. In SQL, WHERE filters individual rows before aggregation, while HAVING applies conditions to the results of aggregate functions like SUM, COUNT, or AVG. Option D is correct because the query uses HAVING to restrict which grouped results appear in the final output.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Sort the results in descending order
Why it's wrong here
Sorting is done by ORDER BY.
- ✗
Join two tables
Why it's wrong here
Joins are performed using JOIN clauses.
- ✗
Filter rows before grouping
Why it's wrong here
That is the purpose of WHERE, not HAVING.
- ✓
Filter groups after aggregation
Why this is correct
HAVING filters groups that meet the aggregate condition.
Go deeper
Related to this question
About these practice questions
This DA0-002 question is part of Courseiva's 986-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DA0-002 practice question is part of Courseiva's free CompTIA 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 DA0-002 exam.