LeetCode 182: Duplicate Emails
Easy Approach to Solve LeetCode 182

I'm Varchasv, a Data Engineer working on enterprise data integration.
Currently on a 90-problem challenge to level up my technical skills and switch to a more development-focused role.
What I'm doing:
- Solving 2 Leetcode problems daily (SQL + DSA).
- Blogging about each problem.
- Building in public.
My Goal - Land a better data engineering role by mid-2026.
Follow my journey !!
Date: January 16, 2026
Category: SQL
Time Taken: 3 minutes
Difficulty: Easy
Problem Statement
Write a solution to report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.
Link: Duplicate Emails
My Approach
Initial thought: I can count how often each email appears in the table and filter out those with a count > 1. I can use a CTE to get the counts and then apply the filter to that CTE.
Final solution:
The best solution is to use the HAVING clause with the GROUP BY clause, so we don't need to create a CTE.
Why this works:
This works because the HAVING clause lets us use aggregation logic for comparison, which the WHEREclause does not allow.
Solution Code
SELECT email AS Email
FROM Person
GROUP BY email
HAVING COUNT(*) > 1
Key Takeaway: Learned more about HAVING clause and when to use it.
Pattern: GROUP BY
Mistakes I Made: I already knew about the HAVING clause and still didn’t implement it because I forgot how it actually worked.
Series: 90 Days of Data Engineering Progress: 7/90 problems completed
Tags: #DEQuest #LeetCode #SQL #DataEngineering #BuildInPublic