2017-02-24 66 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