-- 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 )
不能先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
使用子查询即可解决这个问题。delete from Awhere id in (select id from B)。参考:php程序员,雷雪松的个人博客,欢迎加网站底部的群一起交流MySQL相关的技术。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)