SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1; is run. What does it return?
Correct answer
D. One row per duplicated email, with the number of occurrences in the count column
15 views
D. One row per duplicated email, with the number of occurrences in the count column
15 views
HAVING filters groups after aggregation, so only emails whose group count exceeds one survive, and each surviving group contributes a single output row carrying its count. Without HAVING, GROUP BY email alone would return every distinct email with its count. This query is the standard duplicate-detection pattern before enforcing a unique constraint.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.