我试图查找具有重复值的行,但仅基于选定的列数,而不是单列或整行。例如,如果我的表格如下所示:
ID Address State Name
-------------------------------
0 7 Brown NY John
1 3 Red WX Jane
2 7 Brown WX Ted
3 7 Brown NY Fred
我的问题是:
Find all ID's for rows where the row's Address and State field matched another row's Address and State field.
此查询的答案是:
ID Address State Name
------------------------------
0 7 Brown NY John
3 7 Brown NY Fred
有什么想法吗?
建议: How to select multiple columns values same rows from single table
最佳答案
尝试以下操作:
SELECT A.*
FROM YourTable A
INNER JOIN (SELECT Address, State
FROM YourTable
GROUP BY Address, State
HAVING COUNT(*) > 1) B
ON A.Address = B.Address AND A.State = B.State
关于sql - 查找多列中具有相同值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11056235/