我有一个生成结果的查询:
SELECT urenID FROM uren WHERE uren.urenDossierID IN (SELECT dossierID FROM dossier WHERE dossierKlantID NOT IN (SELECT klantID from klant))
现在我想删除生成该查询的所有记录。现在是我的问题;怎么做?
我有一个生成结果的查询:
SELECT urenID FROM uren WHERE uren.urenDossierID IN (SELECT dossierID FROM dossier WHERE dossierKlantID NOT IN (SELECT klantID from klant))
现在我想删除生成该查询的所有记录。现在是我的问题;怎么做?
只需替换SELECT urenID
为DELETE
DELETE FROM uren WHERE uren.urenDossierID IN (SELECT dossierID FROM dossier WHERE dossierKlantID NOT IN (SELECT klantID from klant))
试试这个。
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)))
我坚信JOIN
比IN
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