Machine-translated by Google. Questions are authored in English.
Top

Discussion

The HAVING clause does which of the following?

  • A.Acts like a WHERE clause but is used for groups rather than rows.
  • B.Acts like a WHERE clause but is used for rows rather than columns.
  • C.Acts like a WHERE clause but is used for columns rather than groups.
  • D.Acts EXACTLY like a WHERE clause.

Answer: A

Correct answer: Acts like a WHERE clause but is used for groups rather than rows.

HAVING filters after aggregation, WHERE before it, and the order is what makes them different rather than redundant.

WHERE decides which rows enter the groups; GROUP BY forms them; HAVING then decides which groups survive, and it may test aggregate values. So HAVING COUNT(*) > 5 is legal and WHERE COUNT(*) > 5 is not, because at the time WHERE runs no group exists to count. That is also why filtering on plain columns belongs in WHERE, where it reduces the work.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.