手机
当前位置:查字典教程网 >编程开发 >mysql数据库 >查询实现删除
查询实现删除
摘要:ifobject_id('t0807')isnotnulldroptablet0807gocreatetablet0807(AutoIDin...

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查询的性能优化基础教程

使MySQL查询区分大小写的实现方法

jsp操作MySQL实现查询/插入/删除功能示例

MySQL 实用命令

MySQL 添加列,修改列,删除列

MySQL里面的子查询实例

mysql 复制记录实现代码

mysql 队列 实现并发读

mysql 查询表中平均分最低的班级

MySQL更新和删除

精品推荐
分类导航