2017-02-24 71 views
-1

请更正下面的sql查询。 这里的列是动态的。 所以我只有用户*。 查询:SQL查询,要显示所有列的重复值

SELECT * FROM test_table WHERE Id IN ('abc','123') GROUP BY Id HAVING COUNT(*) > 1 
+0

“列是动态的” 你问然后我们去修正错误的东西。 – Strawberry

+0

[在MySQL中查找重复值]可能的副本(http://stackoverflow.com/questions/688549/finding-duplicate-values-in-mysql) – davejal

+0

http://stackoverflow.com/q/688549/3664960找到重复值的许多变体 – davejal

回答

0

如果您想选择所有对应于所选的ID列:

select * 
from test_table 
where id in (
     select id 
     from test_table 
     where Id in ('abc','123') 
     group by Id 
     having COUNT(*) > 1 
     ) 

仅供编号:

select id 
from test_table 
where Id in ('abc','123') 
group by Id 
having COUNT(*) > 1