1. Home
  2. Computer Science MCQs
  3. MySQL
  4. When do we use a HAVING clause?

Added 19 Jan 2024

When do we use a HAVING clause?

  1. To limit the output of  a query
  2. To limit the output of a query using an aggregate function only Correct answer
  3. When GROUP by is used
  4. Both a and c above

Correct answer

B. To limit the output of a query using an aggregate function only

19 views

MCQSEXAM

Explanation

HAVING is used to limit the output of a query using an aggregate function. WHERE filters individual rows before grouping and cannot contain aggregates such as COUNT() or SUM(); HAVING filters the groups afterwards.

Example: SELECT dept, COUNT(*) FROM staff GROUP BY dept HAVING COUNT(*) > 5;.

Practise more Database Management Systems MCQs with answers and explanations on MCQsExam.com.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More MySQL MCQs

Practise all MySQL MCQs

Similar MCQs