MSSQL取得或删除重复数据

1.取得不重复的数据

select * from Persons where Id in
(
SELECT    MAX(Id) AS Expr1
FROM    Persons
GROUP BY Name, Gender
)

2.删除重复的数据【MAX换成MIN会有不同的效果】(group by之后数据重复的只会留下一条)

delete from Persons
where Id not in
(
SELECT    MAX(Id) AS Expr1
FROM    Persons
GROUP BY Name, Gender
)
posted @ 2015-10-14 21:05  ZuQing  阅读(216)  评论(0编辑  收藏  举报