Subject | RE: [firebird-support] How to do a join delete with Flamerobin V 0.9.2.1851 |
---|---|
Author | Svein Erling Tysvær |
Post date | 2013-03-20T09:07:54Z |
>>SELECT a.INV_PARTNUMBER, a.INV_ALTPARTNUMBER, b.INVSUP_SUPPNUM,I think it is rather unlikely that he wants a WHERE clause with no correlation between the DELETE and EXISTS. Rather, I expect him to desire something like:
>>a.INV_DESCRIPTION1, a.INV_DESCRIPTION2, a.INV_LOCATIONID, a.INV_UOMID,
>>a.INV_DEPTID, a.INV_STOCKONHAND, a.INV_COUNTEDDATE FROM INVENTORY a
>>join INVENTORY_SUPPLIER b on a.INV_ID = b.INVSUP_INVID where
>>a.INV_COUNTEDDATE < '01.10.2012, 00:00:00.001'
>>and a.inv_locationid = -1
>>and b.INVSUP_SUPPNUM = 10
>
>DELETE FROM INVENTORY a1
>WHERE
>a1.INV_COUNTEDDATE < '01.10.2012, 00:00:00.001'
>AND a1.inv_locationid = -1
>AND EXISTS
> (SELECT 1 FROM INVENTORY a
> JOIN INVENTORY_SUPPLIER b
> ON b.INVSUP_INVID = a.INV_ID
> WHERE b.INVSUP_SUPPNUM = 10)
DELETE FROM INVENTORY a
WHERE a.INV_COUNTEDDATE < '01.10.2012, 00:00:00.001'
AND a.INV_LOCATIONID = -1
AND EXISTS(SELECT * FROM INVENTORY_SUPPLIER b
WHERE a.INV_ID = b.INVSUP_INVID
AND b.INVSUP_SUPPNUM = 10)
Kjells comment regarding performance and EXECUTE BLOCK is the way to go in circumstances like he describe (don't use EXISTS to delete a handful of records from a table of 170 million records), but with smaller tables, EXISTS can be very useful.
HTH,
Set