sqlserver 去重复数据

如果表中有ID

SELECT * FROM   dbo.tblMainUser WHERE ID NOT IN (SELECT MAX(ID) FROM tblMainUser GROUP BY UserName,pwd)

 如果表中没有自增ID

SELECT IDENTITY(INT,1,1) AS id,* INTO #temp FROM TblTest1

SELECT *FROM  #temp WHERE id in(     
SELECT MAX(id)FROM #temp GROUP BY  UserName,Pwd HAVING count(*)>1 )    

 

posted @ 2019-10-24 19:13  牧夫座  阅读(997)  评论(0编辑  收藏  举报