search

Home  >  Q&A  >  body text

php - What is wrong with this sql statement?

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

How should this statement be changed appropriately?

某草草某草草2771 days ago683

reply all(4)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-05 11:11:23

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

    reply
    0
  • 过去多啦不再A梦

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

    You want to delete the user_id that cannot be found in the li_user table? Why not just use:

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

    reply
    0
  • 習慣沉默

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

    Your subquery and delete operations are on the same table. You cannot query and update the same table at the same time.
    Just change to join mode.

    reply
    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)

    reply
    0
  • Cancelreply