删除选择(错误1093)

时间:2015-07-07 13:34:08

标签: mysql

我需要删除此查询中的结果:

SELECT a.cad_id
FROM `Cad` a
WHERE NOT EXISTS
(
SELECT b.cad_id
FROM `rel` b
WHERE a.cad_id = b.rel
)

我试试:

DELETE FROM `Cad` WHERE cad_id = (
SELECT a.cad_id
FROM `Cad` a
WHERE NOT EXISTS
(
SELECT b.cad_id
FROM `rel` b
WHERE a.cad_id = b.rel
)
)

1093 - 您无法在FROM子句

中指定目标表'Cad'进行更新

我该如何解决?

1 个答案:

答案 0 :(得分:0)

在临时表中选择内部查询数据。

DELETE FROM `cad` 
WHERE  cad_id IN (SELECT * 
                 FROM  (SELECT a.cad_id 
                        FROM   `cad` a 
                        WHERE  NOT EXISTS (SELECT b.cad_id 
                                           FROM   `rel` b 
                                           WHERE  a.cad_id = b.rel)) AS 
                       tempTable)