Which of the following describes the HAVING clause?

Study for the Database Systems Test. Prepare with flashcards and multiple choice questions, each with hints and explanations. Get ready for success!

Multiple Choice

Which of the following describes the HAVING clause?

Explanation:
The HAVING clause is used to filter groups after the data has been grouped and aggregates have been computed. When you use GROUP BY, you create groups and calculate an aggregate for each group. HAVING then applies a condition to those grouped results, deciding which groups to keep. For example, grouping by department and counting employees, you can keep only departments with more than five employees: SELECT department, COUNT(*) AS count_emp FROM employees GROUP BY department HAVING COUNT(*) > 5. Here, the filter relies on an aggregate value, which is why it belongs after the grouping step. If you tried to filter before grouping, you’d use WHERE, which cannot reference aggregates. Sorting is done with ORDER BY, not HAVING, and defining the groups is done with GROUP BY.

The HAVING clause is used to filter groups after the data has been grouped and aggregates have been computed. When you use GROUP BY, you create groups and calculate an aggregate for each group. HAVING then applies a condition to those grouped results, deciding which groups to keep. For example, grouping by department and counting employees, you can keep only departments with more than five employees: SELECT department, COUNT() AS count_emp FROM employees GROUP BY department HAVING COUNT() > 5. Here, the filter relies on an aggregate value, which is why it belongs after the grouping step. If you tried to filter before grouping, you’d use WHERE, which cannot reference aggregates. Sorting is done with ORDER BY, not HAVING, and defining the groups is done with GROUP BY.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy