Given a table users with columns id and email, which query returns all emails that appear more than once?
Use GROUP BY to group emails and HAVING to filter groups by count.
Option A correctly groups emails and filters groups with more than one occurrence using HAVING. Options B, C, and D misuse WHERE or HAVING clauses or their order.
Which query returns product names that appear more than once in the products table along with how many times they appear?
Use GROUP BY and HAVING to filter duplicates and COUNT(*) to get counts.
Option A correctly groups by name, counts occurrences, and filters groups with more than one. Option A misses the count column. Options A and B misuse WHERE or HAVING clauses.
Which query is syntactically correct and returns usernames that appear more than once in the accounts table?
Remember that HAVING filters groups after GROUP BY, while WHERE filters rows before grouping.
Only option D uses the correct syntax: GROUP BY followed by HAVING. Options A, C, and D misuse WHERE or HAVING clauses or their order.
You want to find duplicate email values in a very large subscribers table efficiently. Which approach is best?
Indexes speed up grouping and counting on large datasets.
Option C uses an index to speed up grouping and counting, making it efficient. Options B and D rely on scanning or application-side processing, which is slower. Option C scans without indexes, which is inefficient.
Consider a table contacts with a nullable phone column. Which statement about finding duplicates in phone is true?
Think about how SQL treats NULLs in grouping.
In SQL, NULLs are treated as equal for GROUP BY purposes, so multiple NULLs form one group and are counted as duplicates if more than one. Therefore, option B is correct.