背景:
create table test as select * from bda_objects;
insert into test select * from test;
此时test表,有2份数据是重复的,需求:
把所有重复的数据删除,只保留一份数据。
用exists删:
delete test a
where exists(select b.object_id
from test b
where a.object_id = b.object_id
and a.rowid < b.rowid);——成功
等价改成用in删:
delete test a
where a.object_id in (select b.object_id
from test b
where a.object_id = b.object_id
and a.rowid < b.rowid);——成功——为啥这样写就能成功?
改成这样的:
delete test a
where a.rowid in (select b.rowid
from test b
where a.object_id = b.object_id
and a.rowid < b.rowid);——失败,删除0条——不知道为啥?