我正在尝试找到具有重复值的行,但仅基于选定列数,而不是单列或整行.例如,如果我的表格如下所示:
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