注册 登录
编程论坛 ASP技术论坛

请教删除数据库表中重复数据的sql问题

jiushini50 发布于 2007-11-29 12:52, 763 次点击
我的建立的表tbl如下:
id tid mid
1   1   1
2   2   1
3   3   2
4   4   2
5   5   3
6   6   3
我要删除字段mid中重复的数据,并保留一条数据请问这样的sql语句怎么写,我用的sql server
2 回复
#2
MikeFT2007-11-29 13:12
distinct mid
#3
madpbpl2007-11-29 13:30
create table tb1(
id decimal(10),
tid decimal(10),
mid decimal(10)
)

insert into tb1 values(1,1,1)
insert into tb1 values(2,2,1)
insert into tb1 values(3,3,2)
insert into tb1 values(4,4,2)
insert into tb1 values(5,5,3)
insert into tb1 values(6,6,3)

select min(id),min(tid),mid from [tb1] group by mid


drop table tb1

刚学sql server,前面的数据类型定义有些问题,但是sql是对的,已经测试通过
1