24 个解决方案
#1
delete from table1 where id = (select distinct id from table1 where field1 = value1 )
#2
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
#3
但是两条记录完全一样,无id标识区分
字段譬如 bh xx
内容 3 y2
3 y2
想用sql删去一条
字段譬如 bh xx
内容 3 y2
3 y2
想用sql删去一条
#4
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
#5
学习
#6
leonwan(I walk alone) 大大: 没有rowid啊
#7
distinct
#8
19、说明:删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
#9
delete from table1 where id = (select distinct id from table1 where field1 = value1 )
#10
没有id区分,估计删除完全相同的单个记录,应该是不可能的吧
#11
是阿,很难删阿,有id的的确简单的
#12
sqlserver的表中不可能出现两条完全相同的数据。怎么找也得有个自动增加的主键吧,用主键区分。
#13
还是想想为什么会有一样的数据吧
#14
ding
#15
删除前临时存储一条,然后都删除,然后在添加先前临时存储的一条就可以了撒
#16
csdn上那么多数据库论坛多问问,这种问题在哪里比较基础。
#17
xiaoweioo(小玮) 大大:表中会出现相同的,只要字段无约束,都可为空
lsj_zrp() 大大:这个方法行得通,先写入一临时表,然后删除后回写,但步骤比较复杂。
真的没有可以用sql直接搞定的吗,唉!
lsj_zrp() 大大:这个方法行得通,先写入一临时表,然后删除后回写,但步骤比较复杂。
真的没有可以用sql直接搞定的吗,唉!
#18
恩~用临时表是个办法
先查询表中不完全相同的记录,把结果集插入到临时表.再把数据转过来就行了
先查询表中不完全相同的记录,把结果集插入到临时表.再把数据转过来就行了
#19
不大可能吧..sql2000是不允许有两条完全相同的记录的..你看你的字段值的最后有没有多出一个空格的,有可能会忽略这么一个问题的..完全相同好像不会的..
#20
distinct
#21
两条完全相同的记录存在于一个数据表本来就是一个错误
#22
建议应该反思一下为什么会出现一样的两行数据,设计数据库表都不设计主键…………人才
#23
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
================================
在oracle中可以用这个方法,因为rowid是伪列,任何一个表都可以使用。
sql server不清楚。
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
================================
在oracle中可以用这个方法,因为rowid是伪列,任何一个表都可以使用。
sql server不清楚。
#24
表中如果没有自动编号的那一列,可以在查询的时候增加一个序列(详细方法sql帮助中有),然后将字段分组,删除top1 的记录
#1
delete from table1 where id = (select distinct id from table1 where field1 = value1 )
#2
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
#3
但是两条记录完全一样,无id标识区分
字段譬如 bh xx
内容 3 y2
3 y2
想用sql删去一条
字段譬如 bh xx
内容 3 y2
3 y2
想用sql删去一条
#4
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
#5
学习
#6
leonwan(I walk alone) 大大: 没有rowid啊
#7
distinct
#8
19、说明:删除重复记录
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
#9
delete from table1 where id = (select distinct id from table1 where field1 = value1 )
#10
没有id区分,估计删除完全相同的单个记录,应该是不可能的吧
#11
是阿,很难删阿,有id的的确简单的
#12
sqlserver的表中不可能出现两条完全相同的数据。怎么找也得有个自动增加的主键吧,用主键区分。
#13
还是想想为什么会有一样的数据吧
#14
ding
#15
删除前临时存储一条,然后都删除,然后在添加先前临时存储的一条就可以了撒
#16
csdn上那么多数据库论坛多问问,这种问题在哪里比较基础。
#17
xiaoweioo(小玮) 大大:表中会出现相同的,只要字段无约束,都可为空
lsj_zrp() 大大:这个方法行得通,先写入一临时表,然后删除后回写,但步骤比较复杂。
真的没有可以用sql直接搞定的吗,唉!
lsj_zrp() 大大:这个方法行得通,先写入一临时表,然后删除后回写,但步骤比较复杂。
真的没有可以用sql直接搞定的吗,唉!
#18
恩~用临时表是个办法
先查询表中不完全相同的记录,把结果集插入到临时表.再把数据转过来就行了
先查询表中不完全相同的记录,把结果集插入到临时表.再把数据转过来就行了
#19
不大可能吧..sql2000是不允许有两条完全相同的记录的..你看你的字段值的最后有没有多出一个空格的,有可能会忽略这么一个问题的..完全相同好像不会的..
#20
distinct
#21
两条完全相同的记录存在于一个数据表本来就是一个错误
#22
建议应该反思一下为什么会出现一样的两行数据,设计数据库表都不设计主键…………人才
#23
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
================================
在oracle中可以用这个方法,因为rowid是伪列,任何一个表都可以使用。
sql server不清楚。
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
================================
在oracle中可以用这个方法,因为rowid是伪列,任何一个表都可以使用。
sql server不清楚。
#24
表中如果没有自动编号的那一列,可以在查询的时候增加一个序列(详细方法sql帮助中有),然后将字段分组,删除top1 的记录