最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
查询实现删除
时间:2008-07-17 编辑:简简单单 来源:一聚教程网
if object_id('t0807') is not null
drop table t0807
go
create table t0807(AutoID int identity(1,1) primary key,[id] int,username varchar(10))
go
insert into t0807
select 1,'1' union all
select 4,'1' union all
select 4,'2' union all
select 6,'2' union all
select 2,'3' union all
select 7,'3'
go
--主键AutoID
delete from t0807
where AutoID not in
(
--查找出最小值
select AutoID from t0807 a
where [id]<=
(select min([id]) from t0807 b where a.username=b.username)
)
go
select * from t0807
(所影响的行数为 6 行)
(所影响的行数为 3 行)
AutoID id username
----------- ----------- ----------
1 1 1
3 4 2
5 2 3
(所影响的行数为 3 行)
-
上一个: 怎么读取用户多选的调查
相关文章
- MySQL登录、访问及退出操作解析 10-18
- sql语句 update字段null不能用is null问题解析 09-28
- SQL Server ISNULL 不生效原因及解决分析 09-28
- 关于if exists的用法及说明分析 09-28
- Access数据库日常维护方法 09-28
- Oracle 删除大量表记录操作介绍 09-27