我正在使用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
)
)
答案 0 :(得分:2)
DELETE m
FROM 1masterinventory m
LEFT JOIN 1amazoninventory a ON a.rid = m.rid
WHERE a.rid IS NULL;