Skip to content
Advertisement

Show All Duplicate Records QUERY

What is the query that will show all the records that have multiple names?

For example.

Table 1:

| ID | Name    | Age   | Email           |
+----+---------+-------+-----------------+
| 1  | Mike    | 12    | mike@gmail.com  |
| 2  | Mon     | 10    | mon@gmail.com   |
| 3  | Peter   | 12    | pet@gmail.com   |
| 4  | Mike    | 13    | mike12@gmail.com|

Desired result:

| ID | Name    | Age   | Email           |
+----+---------+-------+-----------------+
| 1  | Mike    | 12    | mike@gmail.com  |
| 4  | Mike    | 13    | mike12@gmail.com|

Advertisement

Answer

You can use GROUP BY and join result to origin table

SELECT t1.*
FROM myTable t1

JOIN

  (SELECT Name
   FROM myTable
   GROUP BY Name
   HAVING COUNT(Name) > 1) t2

ON t1.Name = t2.Name
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement