如果目标表在from子句中,是否可以删除MySQL中的多行?

时间:2014-09-15 17:06:00

标签: mysql sql phpmyadmin

我正在使用PHPMYAdmin和MySQL数据库。我想从表1masterinventory中删除不在1amazoninventory(PK RID)中的所有行(PK RID)。我觉得这个查询应该有效,但我收到错误“#1093 - 您无法在FROM子句中为更新指定目标表'1masterinventory'。”

 DELETE FROM 1masterinventory 
 WHERE rid IN
     (
        SELECT rid 
        FROM 1masterinventory 
        WHERE rid NOT IN
         (
           SELECT rid FROM 
           1amazoninventory WHERE 1
         )
    )

1 个答案:

答案 0 :(得分:2)

SQL Fiddle

DELETE m
FROM 1masterinventory m
LEFT JOIN 1amazoninventory a ON a.rid = m.rid
WHERE a.rid IS NULL;