Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all rows that have a duplicate entry in a particular column in MySQL table

Despite a good deal of searching I haven't come up with the correct method of listing all columns for rows that have the same content in a particular column (let's say the column 'Name').

So if my table, called USERS, had the following content:

ID      User      Name

1       Nick      Nick
2       NickP     Nick
3       NickC     Nick
4       John      John
5       Brian     Brian

The SELECT statement should return:

ID      User      Name

1       Nick      Nick
2       NickP     Nick
3       NickC     Nick

As these are all the rows that contain the same content in column 'Name'. How would I write this?

like image 969
Nick Avatar asked Nov 17 '25 20:11

Nick


1 Answers

How about this?

SELECT * FROM Users WHERE Name IN(SELECT Name FROM Users GROUP BY Name HAVING COUNT(1) > 1)
like image 130
xbrady Avatar answered Nov 20 '25 11:11

xbrady



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!