0
0
SQLquery~20 mins

Finding duplicates efficiently in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Duplicate Finder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find duplicate emails in a users table

Given a table users with columns id and email, which query returns all emails that appear more than once?

ASELECT email FROM users GROUP BY email HAVING COUNT(*) > 1;
BSELECT email FROM users WHERE COUNT(email) > 1;
CSELECT email FROM users GROUP BY email WHERE COUNT(*) > 1;
DSELECT email FROM users HAVING COUNT(email) > 1 GROUP BY email;
Attempts:
2 left
💡 Hint

Use GROUP BY to group emails and HAVING to filter groups by count.

query_result
intermediate
2:00remaining
Retrieve duplicate product names with their counts

Which query returns product names that appear more than once in the products table along with how many times they appear?

ASELECT name, COUNT(*) FROM products GROUP BY name HAVING COUNT(*) > 1;
BSELECT name, COUNT(*) FROM products GROUP BY name WHERE COUNT(*) > 1;
CSELECT name, COUNT(*) FROM products WHERE COUNT(name) > 1 GROUP BY name;
DSELECT name FROM products GROUP BY name HAVING COUNT(*) > 1;
Attempts:
2 left
💡 Hint

Use GROUP BY and HAVING to filter duplicates and COUNT(*) to get counts.

📝 Syntax
advanced
2:00remaining
Identify the correct query to find duplicate usernames

Which query is syntactically correct and returns usernames that appear more than once in the accounts table?

ASELECT username FROM accounts HAVING COUNT(username) > 1 GROUP BY username;
BSELECT username FROM accounts WHERE COUNT(username) > 1 GROUP BY username;
CSELECT username FROM accounts GROUP BY username WHERE COUNT(*) > 1;
DSELECT username FROM accounts GROUP BY username HAVING COUNT(*) > 1;
Attempts:
2 left
💡 Hint

Remember that HAVING filters groups after GROUP BY, while WHERE filters rows before grouping.

optimization
advanced
2:00remaining
Optimize duplicate detection on large tables

You want to find duplicate email values in a very large subscribers table efficiently. Which approach is best?

AScan the entire table without indexes using <code>GROUP BY email HAVING COUNT(*) > 1</code>.
BUse <code>SELECT DISTINCT email FROM subscribers</code> and then count duplicates in application code.
CCreate an index on the <code>email</code> column and use <code>GROUP BY email HAVING COUNT(*) > 1</code>.
DUse a subquery with <code>WHERE email IN (SELECT email FROM subscribers GROUP BY email HAVING COUNT(*) > 1)</code> without indexes.
Attempts:
2 left
💡 Hint

Indexes speed up grouping and counting on large datasets.

🧠 Conceptual
expert
2:00remaining
Understanding duplicate detection with NULL values

Consider a table contacts with a nullable phone column. Which statement about finding duplicates in phone is true?

AGROUP BY phone causes an error if NULL values exist.
BGROUP BY phone treats all NULLs as one group, so duplicates of NULL are counted.
CGROUP BY phone ignores NULLs, so duplicates of NULL are never detected.
DGROUP BY phone treats each NULL as distinct, so duplicates of NULL are not counted.
Attempts:
2 left
💡 Hint

Think about how SQL treats NULLs in grouping.