How can I select all rows in MySQL where a particular field value is not unique. For example I have the following data:
---------------------------------------
| ID | Name | URL |
---------------------------------------
| 1 | Store 1| http://www.store1.com |
| 2 | Store 2| http://www.store1.com |
| 3 | Store 3| http://www.store3.com |
| 4 | Store 4| http://www.store4.com |
| 5 | Store 5| http://www.store4.com |
---------------------------------------
In this I would want to return the following where the URL field has duplicates:
---------------------------------------
| ID | Name | URL |
---------------------------------------
| 1 | Store 1| http://www.store1.com |
| 2 | Store 2| http://www.store1.com |
| 4 | Store 4| http://www.store4.com |
| 5 | Store 5| http://www.store4.com |
---------------------------------------
or, old school...
SELECT DISTINCT x.*
FROM my_table x
JOIN my_table y
ON y.url = x.url
AND y.id <> x.id
ORDER
BY id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With