Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for SQL to find records with duplicates?

Can I use a SQL query to find records where one field is identical in both? That is, can I use the following table and return 1,3 (the ids) by comparing the name columns (and ignoring the phone)?

    ID | Name | Phone

    1  | Bob  | 5555555555
    2  | John | 1234567890
    3  | Bob  | 1515151515
    4  | Tim  | 5555555555
like image 548
waiwai933 Avatar asked Jan 13 '10 00:01

waiwai933


1 Answers

To get all names that exist more than once you can execute this statement:

SELECT Name FROM People GROUP BY Name HAVING COUNT(*)>1;
like image 131
Joachim Sauer Avatar answered Nov 02 '22 03:11

Joachim Sauer