mysql中删除数据不可以用子查询吗?
select*fromonewhereoneNamein(selectoneNamefromonegroupbyOneName,OneAge,oneSex,oneAddr...
select * from one where oneName in (select oneName from one
group by OneName,OneAge,oneSex,oneAddress having count(oneName) > 1 )
用select 可以查询到数据,
delete from one where oneName in (select oneName from one
group by OneName,OneAge,oneSex,oneAddress having count(oneName) > 1 )
用delete总是报错,You can't specify target table 'one' for update in From clause
删除数据为什么不能用子查询?
为什么呢?求大神帮帮忙 展开
group by OneName,OneAge,oneSex,oneAddress having count(oneName) > 1 )
用select 可以查询到数据,
delete from one where oneName in (select oneName from one
group by OneName,OneAge,oneSex,oneAddress having count(oneName) > 1 )
用delete总是报错,You can't specify target table 'one' for update in From clause
删除数据为什么不能用子查询?
为什么呢?求大神帮帮忙 展开
2个回答
展开全部
不能先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;
追问
为什么不能这样使用啊?求大神解释一下,谢谢
追答
mysql所限啊,只能说明mysql不够强大,还需要完善,Oracle能够实现
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |