Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding duplicate email addresses

Tags:

sql

I need to find duplicate emails in our database. I am looking on one table for this information. What I have so far

 SELECT name.email, name.ID

 From Name
 Group BY Name.ID, Name.EMAIL
 Having Count(*) > 1

I know that its wrong, but not sure how to write it appropriately.

like image 207
user2135808 Avatar asked Mar 05 '13 12:03

user2135808


People also ask

Is there a way to find duplicate emails in Outlook?

Select a mailbox folder. Select Home > Cleanup. Now, configure the below options: Clean up Conversation will delete and move the duplicate emails that are in the conversation.

Does Gmail allow duplicate email addresses?

The problem: Gmail allows multiple e-mail addresses for a single account.


4 Answers

remove the ID

 SELECT name.email
 From   Name
 Group  BY Name.EMAIL
 Having Count(*) > 1

if you want to get the number of email,

 SELECT name.email, COUNT(*) totalEmailCount
 From   Name
 Group  BY Name.EMAIL
 Having Count(*) > 1
like image 55
John Woo Avatar answered Oct 20 '22 05:10

John Woo


The query would be

SELECT name.email, COUNT(*) FROM Name 
GROUP BY Name.email HAVING COUNT(*) > 1

What you need to know is that if you group also by ID the count would be 1, thats why your query didn't work.

If you need to know the IDs of the users with emails duplicated you can do this:

select Name.ID, Name.Email from Name where Name.Email in (

SELECT name.email FROM Name 
    GROUP BY Name.email HAVING COUNT(*) > 1
)
like image 25
Luis Tellez Avatar answered Oct 20 '22 04:10

Luis Tellez


The below SQL query will return the ID and EMAIL of the first matching row which contain the same(duplicate) EMAIL

select ID, EMAIL from Name group by EMAIL having count(EMAIL) > 1

If someone, wants all the duplicate EMAIL from the Name table then, he/she can execute the following SQL query

select EMAIL from Name group by EMAIL having count(EMAIL) > 1

Note that: SQL is a fully case-insensitive language.

like image 44
Shubham Prasad Avatar answered Oct 20 '22 04:10

Shubham Prasad


Here you go:

SELECT name.email, COUNT(*)
FROM
    Name
GROUP BY
    Name.email
HAVING 
    COUNT(*) > 1
like image 29
Vishal Suthar Avatar answered Oct 20 '22 04:10

Vishal Suthar