How to select duplicate rows in SQL

Submitted 2 years, 12 months ago
Ticket #421
Views 366
Language/Framework SQL
Priority Low
Status In-Progress

This query will give us John, Sam, Tom, Tom because they all have the same email.

However, what I want is to get duplicates with the same email and name.

That is, I want to get "Tom", "Tom".

Submitted on Apr 27, 21
add a comment

2 Answers

This might help: FInd duplicates (https://chartio.com/learn/databases/how-to-find-duplicate-values-in-a-sql-table/)

Or, maybe stackoverflow (https://stackoverflow.com/questions/4522431/find-duplicate-entries-in-a-column)

Submitted 2 years, 12 months ago

There are many ways to do this,

one of them below,

SELECT a.*
FROM users a
JOIN (SELECT username, email, COUNT(*)
FROM users 
GROUP BY username, email
HAVING count(*) > 1 ) b
ON a.username = b.username
AND a.email = b.email
ORDER BY a.email

Submitted 2 years, 11 months ago


Latest Blogs