mysql的1093错误You can't specify target table 't' for update in FROM clause 简单解决

来源:互联网 发布:淘宝双十二承接页装修 编辑:程序博客网 时间:2024/05/31 19:08

mysql>delete from twhere idin (select idfrom twhere id < 5);  

ERROR1093 (HY000): You can't specify target table 't' for update in FROM clause

改为下面就OK

deletefrom t where id in(select * from ((select idfrom twhere id <5) tmp);  

主句(select * from (从句 temp)



删除重复,但保留最小id项。

 DELETE
FROM
    file
WHERE
    fileaddress IN (
    select * from ((
        SELECT
            fileaddress 
        FROM
            file
        GROUP BY
            fileaddress
        HAVING
            count(fileaddress) > 1
            ) a)
    )
AND id NOT IN (
 select * from ((
    SELECT
        min(id)
    FROM
        file
    GROUP BY
        fileaddress
    HAVING
        count(fileaddress) > 1
         ) b)
)   


0 0
原创粉丝点击