The HAVING clause in SQL is used to filter grouped results after aggregation, whereas WHERE filters rows before grouping. It’s a key part of data analysis when working with the GROUP BY clause and aggregate functions like SUM(), COUNT(), and AVG().
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
What is the primary purpose of the HAVING clause in SQL?
Correct
Incorrect
Question 2 of 15
2. Question
Which clause does the HAVING clause work closely with?
Correct
Incorrect
Question 3 of 15
3. Question
Which of the following clauses is used to filter rows before they are grouped?
Correct
Incorrect
Question 4 of 15
4. Question
Identify the correct usage of HAVING:
SELECT department, COUNT(*) FROM employees GROUP BY department ??? COUNT(*) > 5;
Correct
Incorrect
Question 5 of 15
5. Question
Which of the following queries will throw an error?
Correct
Incorrect
Question 6 of 15
6. Question
Which clause comes **after** the `HAVING` clause in SQL syntax (if present)?
Correct
Incorrect
Question 7 of 15
7. Question
Which clause is evaluated first: `HAVING` or `WHERE`?
Correct
Incorrect
Question 8 of 15
8. Question
What does this query return?
SELECT city, COUNT(*) FROM customers GROUP BY city HAVING COUNT(*) > 3;
Correct
Incorrect
Question 9 of 15
9. Question
Can we use `HAVING` without a `GROUP BY` clause?
Correct
Incorrect
Question 10 of 15
10. Question
What is the result of this query?
SELECT COUNT(*) FROM employees HAVING COUNT(*) > 0;
Correct
Incorrect
Question 11 of 15
11. Question
Which clause is used to filter **non-aggregated** columns?
Correct
Incorrect
Question 12 of 15
12. Question
What will be the output?
SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) < 40000;
Correct
Incorrect
Question 13 of 15
13. Question
Why might a query with a correct `HAVING` clause still return no results?
Correct
Incorrect
Question 14 of 15
14. Question
Which of the following is **invalid** usage of `HAVING`?
Correct
Incorrect
Question 15 of 15
15. Question
What keyword would you use if you wanted to filter rows **before** aggregation in this query?
SELECT role, COUNT(*) FROM users ??? role = ‘Admin’ GROUP BY role HAVING COUNT(*) > 1;
Correct
Incorrect
Summary
The HAVING clause in SQL helps you filter grouped and aggregated results. It is typically used alongside the `GROUP BY` clause and aggregate functions like `SUM()`, `AVG()`, and `COUNT()`. Understanding the difference between `WHERE` and `HAVING` is essential for writing clean and effective analytical queries.
At QuizOrbit, our team specializes in fun, informative quizzes across topics like general knowledge, technology, and entertainment. Boost your knowledge with our expert-designed quizzes.