sql 查询表格中多列重复的数据并显示该表的其他列

时间:2021-12-03 15:29:15

我们一般情况下通过分组函数group by来查询重复的列

SELECT *
  FROM (SELECT [column1],[column2] FROM [dbo].[Table] where =) R group by [column1],[column2] having count(*) >

但是查询出的结果不能显示该表的其他列

想要查询一张表中有多个列重复的数据且也要显示该表的其他列

  SELECT M.*
  FROM [dbo].[Table] M,
(SELECT *
  FROM (SELECT [column1],[column2] FROM [dbo].[Table] where 1=1) R group by [column1],[column2] having count(*) > 1) M1
where M.[column1]=M1.[column1] AND M.[column2]=M1.[column2]