不能先select出同一表中的某些值,再update这个表(在同一语句中)
解决方案
--1.把需要删除的数据放到另外的一张表里create table table_test as select oneName from one
group by OneName,OneAge,oneSex,oneAddress having count(oneName) > 1
--2.删除不需要的数据
delete from one where onename in(select oneName from table_test)
--3.删除创建的表
drop table table_test
以id的大小排序,确定最后5条数据。-- oracle
delete from tb_user t3 where t3.id in(
select t2.id from (
select t1.id,ROWNUM as r from tb_user t1 ORDER BY t1.id ) t2
where t2.r<=5)
-- mysql
delete from tb_user t2 where t2.id IN
(select t1.id from tb_user t1 order by t1.id LIMIT 5 )
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)