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

时间:2022-02-23 08:20:53

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