搜索
php - 这条sql语句错在什么地方?
某草草
某草草 2017-06-05 11:09:23
[PHP讨论组]
DELETE from li_make_code  where user_id in 
(    
    select user_id from li_make_code a 
        where 
            not exists (select 1 from li_user b  where b.id=a.user_id)
) ;
[Err] 1093 - You can't specify target table 'li_make_code' for update in FROM clause

这个语句应该怎么改合适

某草草
某草草

全部回复(4)
phpcn_u1582

mysql中You can't specify target table for update in FROM clause错误

过去多啦不再A梦

你是想把user_idli_user表中找不到的给删了吧,为什么不直接用:

delete from li_make_code where user_id not in 
    (select distinct id from li_user)
習慣沉默

你子查询和删除操作的是同一个表,不能同时查询和更新同一个表。
更改为join方式即可。

PHPz

DELETE from li_make_code where user_id in ( SELECT user_id from
(select user_id from li_make_code a where not exists(select 1 from li_user b where b.id=a.user_id)) bb)

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号