Duplicate Emails SQL Challenge - MySQL Solution

1. Introduction

In this blog post, we will address a common SQL query challenge – identifying duplicate email addresses in a MySQL database. This is a typical scenario in data cleaning and verification processes.

Problem

The task is to write a MySQL query that finds all duplicate email addresses in a table.

Database Table:

Person Table:
Id Email
1 john@example.com
2 bob@example.com
3 john@example.com

3. MySQL Solution

SELECT Email
FROM Person
GROUP BY Email
HAVING COUNT(Email) > 1;

Output:

Email
john@example.com

Explanation:

1. The query groups the records in the Person table by Email.

2. The HAVING clause filters out groups that have more than one occurrence of the same email.

3. This approach efficiently identifies duplicate email addresses.

4. The result is a list of email addresses that appear more than once in the table.


Comments