php - 這sql語句錯在哪裡?
某草草
某草草 2017-06-05 11:09:23
0
4
565
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中FROM子句中無法指定更新目標表錯誤

过去多啦不再A梦

你是想把user_idli_user表中找不到的給刪了吧,為什麼不直接用:

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

你子查詢和刪除操作的是同一個表,不能同時查詢和更新同一個表。
改為join方式即可。

PHPzhong

從 li_make_code 中刪除 user_id ( SELECT user_id from
(從 li_make_code a 中選擇不存在的 user_id(從 li_user b 中選擇 1user b.id=a. 其中_id)) bb)

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!