suchen

Heim  >  Fragen und Antworten  >  Hauptteil

php - Was ist an dieser SQL-Anweisung falsch?

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

Wie sollte dieser Satz passend geändert werden

某草草某草草2771 Tage vor686

Antworte allen(4)Ich werde antworten

  • phpcn_u1582

    phpcn_u15822017-06-05 11:11:23

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

    Antwort
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-05 11:11:23

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

    delete from li_make_code where user_id not in 
        (select distinct id from li_user)

    Antwort
    0
  • 習慣沉默

    習慣沉默2017-06-05 11:11:23

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

    Antwort
    0
  • PHPz

    PHPz2017-06-05 11:11:23

    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)

    Antwort
    0
  • StornierenAntwort