1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. SELECT email, COUNT(*) FROM users GROUP BY email HAVING…

Added 30 Nov -0001

SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1; is run. What does it return?

  1. Every row whose email appears more than once in the table, one row per duplicate
  2. One row per distinct email, including those that appear exactly once in users
  3. One row per email, with the count replaced by the number of distinct duplicates
  4. One row per duplicated email, with the number of occurrences in the count column Correct answer

Correct answer

D. One row per duplicated email, with the number of occurrences in the count column

15 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

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

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs