常用(经典)SQL语句汇总贴
背景:最近想好好学习下SQL语言,欢迎大家提供比较常用的或经典的SQL语句!!谢谢!!
转自:青松Blog:http://www.cnblogs.com/piaoqingsong/archive/2006/08/08/470931.html
删除重复数据
1、delete from t1 where exists(select 1 from t1 a where a.id>t1.id and t1.col1=a.col1)
2、alter table t1 add (id int identity(1,1))
delete from t1
where id not in (select min(id) from t1 group by column having count(*) > 0)
3、 delete from music a1 where a1.rowid<>(select max(rowid) from music a2 where a1.id=a2.id )
考虑一下,第一条处理方案最好,方案3也不错,rowid是Oracle特有的,不过根据唯一标识在别的数据库也一样处理