如何选择 MySQL 中特定字段值不唯一的所有行。例如我有以下数据:
---------------------------------------
| 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 |
---------------------------------------
在此,我想在 URL 字段重复的地方返回以下内容:
---------------------------------------
| 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 |
---------------------------------------
最佳答案
或者,老派...
SELECT DISTINCT x.*
FROM my_table x
JOIN my_table y
ON y.url = x.url
AND y.id <> x.id
ORDER
BY id;
关于MySQL - 选择字段值不唯一的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32459166/