You can't specify target table 'hr_uc_user' for update in FROM clause缘由及解决方案

mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。 例以下面这个sql:mysql

delete from  hr_uc_user where 
    (name, code) in (
           select
            name n,
            code cc
        from
            hr_uc_user 
        group by  name,code
        having
            count(*) > 1) 
    )
sql

改为以下:spa

delete from  hr_uc_user wherecode

    (name, code) in (
           select w.n,w.cc from
       (select
            name n,
            code cc
        from
            hr_uc_user 
        group by  name,code
        having
            count(*) > 1) w
    )        ci

相关文章
相关标签/搜索