SQL SERVER可以这么写,其他的数据库可能不行。
delect a
from table1 a
where exists(
select * from table1 b
where a.price=b.price
and a.id>b.id
)
delect a
from table1 a
where exists(
select * from table1 b
where a.price=b.price
and a.id>b.id
)
delect from table1 as a
where exists(
select * from table1 as b
where a.price=b.price
and a.id>b.id
)
还不如将不重复记录倒入临时表中:
insert into temp_table select min(id) as id, price from table1 group by price;
然后倒回来:
drop table table1;
rename table temp_table to table1;
我这样写好像也可以.
delect from table1
where exists(
select * from table1 as b
where table1.price=b.price
and table1.id>b.id
)
呵呵,结果好像也正确,只是可读性太差。