Subject | RE: [firebird-support] How to use DELETE with LEFT JOIN |
---|---|
Author | Svein Erling Tysvær |
Post date | 2012-07-20T07:31:54Z |
>Hi,No LEFT JOIN (or any JOIN) in Firebird DELETE.
>
>I'm newbie with Firebird. Now I try to delete some orphand records using:
>
>DELETE CUEN_DET01.* FROM CUEN_DET01
>LEFT JOIN FACTF01 ON (CUEN_DET01.NO_FACTURA = FACTF01.CVE_DOC)
> AND (CUEN_DET01.CVE_CLIE = FACTF01.CVE_CLPV)
>WHERE FACTF01.CVE_DOC Is Null
Theoretically, I assume your above statement to work out as either not having a match or having a match with CVE_DOC IS NULL. That can be translated as follows:
DELETE FROM CUEN_DET01 C
WHERE NOT EXISTS(SELECT * FROM FACTF01 F
WHERE C.NO_FACTURA = F.CVE_DOC
AND C.CVE_CLIE = F.CVE_CLPV)
OR EXISTS(SELECT * FROM FACTF01 F
WHERE C.NO_FACTURA = F.CVE_DOC
AND C.CVE_CLIE = F.CVE_CLPV
AND F.CVE_DOC IS NULL)
though, of course, the OR EXISTS part would be a most unusual requirement, so I expect that you can delete that.
HTH,
Set