日期:2014-05-17  浏览次数:20415 次

删除表中相同的数据,留下其最后保存的那条数据的sql语句怎么写啊

我有一张表table,里面有两条相同的数据swID:762与766,删除swID较小的那一条数据,
判断两条数据相同的条件是,swCH和swTimes相同

得到的结果是


------解决方案--------------------
delete from table where SWID in(
select SWID from
(
select SWCH,swTimes,max(SWID) as SWID from table group by SWCH,swTimes
) a

)
------解决方案--------------------
[code=SQL][/code]
delete a from table a where exists(select * from table where swch=a.swch and swtimes=a.swtimes and swid>a.swid)