SQL查询,用于显示包含所有列的重复值

时间:2017-02-24 09:31:47

标签: mysql

请更正以下的sql查询。 这里的列是动态的。 所以我只需要用户*。 查询:

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

1 个答案:

答案 0 :(得分: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
        )

仅限Id:

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