SQL DELETE与JOIN在WHERE NULL的多个条件上的另一个表

时间:2013-12-03 19:06:43

标签: mysql sql sql-delete mysql-error-1064

我必须从slaveTable中删除与masterTable表没有更多关系的行(死关系,从masterTable中删除)。

我想出了声明:

DELETE
FROM   slaveTable AS s
LEFT JOIN 
       masterTable AS m 
ON   ( s.key1 = m.key1
AND    s.key2 = m.key2 )
WHERE  m.key1 IS NULL

SQL DELETE with JOIN another table for WHERE condition 这种方式显示为一种解决方案......但对我来说不起作用。 由于我缺乏声誉,我无法回答。

1 个答案:

答案 0 :(得分:1)

指定要删除行的表。

DELETE s                    -- << HERE: s (alias of slaveTable )
FROM   slaveTable AS s
LEFT JOIN 
       masterTable AS m 
ON   ( s.key1 = m.key1
AND    s.key2 = m.key2 )
WHERE  m.key1 IS NULL