删除MySQL子查询

时间:2013-02-02 13:45:42

标签: mysql sql sql-delete

我有一个生成结果的查询:

SELECT urenID FROM uren WHERE uren.urenDossierID IN (SELECT dossierID FROM dossier WHERE dossierKlantID NOT IN (SELECT klantID from klant))

现在我想删除生成该查询的所有记录。现在是我的问题;怎么做?

3 个答案:

答案 0 :(得分:2)

只需将SELECT urenID替换为DELETE

DELETE FROM uren WHERE uren.urenDossierID IN (SELECT dossierID FROM dossier WHERE dossierKlantID NOT IN (SELECT klantID from klant))

答案 1 :(得分:1)

试试这个。

DELETE FROM uren WHERE urenID in (
   SELECT urenID FROM uren WHERE uren.urenDossierID IN (SELECT dossierID FROM dossier WHERE dossierKlantID NOT IN (SELECT klantID from klant)))

答案 2 :(得分:1)

我坚信JOININ

更快
DELETE  a
FROM    uren a
        LEFT JOIN dossier b
            ON a.urenDossierID = b.dossierID
        LEFT JOIN klant c
            ON b.dossierKlantID = c.klantID
WHERE   b.dossierID IS NOT NULL AND
        c.klantID IS NULL