Subject Re: How to use DELETE with LEFT JOIN
Author aaroncg_98
Ok,

Thanks for your help.

But I have some question's, because I don't understand how the sentence works, or how translate the JOIN.

If you have some reference to investigate more, please let me know.


--- In firebird-support@yahoogroups.com, Svein Erling Tysvær <svein.erling.tysvaer@...> wrote:
>
> >Hi,
> >
> >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
>
> No LEFT JOIN (or any JOIN) in Firebird DELETE.
>
> 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
>