SELECT COUNT(*) FROM orders HAVING COUNT(*) > 100; is valid in PostgreSQL. What does HAVING do when no GROUP BY is written?
Correct answer
B. It filters the single implicit group, returning either one row or no rows at all
16 views
B. It filters the single implicit group, returning either one row or no rows at all
16 views
HAVING filters groups, and an aggregate query with no GROUP BY has exactly one implicit group covering all rows, so the clause can return that single row or suppress it entirely. It never filters individual rows; WHERE does that before grouping. Writing HAVING without a GROUP BY is the compact way to ask whether a table is large enough to matter.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.