Subject | RE: [firebird-support] SQL question - update with a join |
---|---|
Author | Svein Erling Tysvær |
Post date | 2008-02-13T07:21:46Z |
Unless things have changed since Firebird 1.5.4, IS is a reserved word, hence make the alias ISU or something.
And one further comment, Bill. With a few exceptions, things in the WHERE clause that refers to a table on the right side of a left join, in reality changes the join to an INNER JOIN only with more restrictions on what the optimizer can do (often a bad idea) and makes your sql more difficult to read (that's often a bad idea, too). As mentioned, there are a few exceptions, but generally, use inner JOINs (that's the default if you just specify JOIN) when possible, and LEFT (RIGHT, OUTER) JOINs when required. Though, as Helens solution shows, you do not want a join at all in this case.
HTH,
Set
-----Original Message-----
From: Helen Borrie
update INVENTORY i
set i.INV_QTYONORDER = 0
where exists
(select 1 from INVENTORY_SUPPLIER is
where is.INVSUP_INVID = i.INV_ID
and is.INVSUP_SUPPNUM = :suppnum
and i.INV_QTYONORDER <> 0)
And one further comment, Bill. With a few exceptions, things in the WHERE clause that refers to a table on the right side of a left join, in reality changes the join to an INNER JOIN only with more restrictions on what the optimizer can do (often a bad idea) and makes your sql more difficult to read (that's often a bad idea, too). As mentioned, there are a few exceptions, but generally, use inner JOINs (that's the default if you just specify JOIN) when possible, and LEFT (RIGHT, OUTER) JOINs when required. Though, as Helens solution shows, you do not want a join at all in this case.
HTH,
Set
-----Original Message-----
From: Helen Borrie
update INVENTORY i
set i.INV_QTYONORDER = 0
where exists
(select 1 from INVENTORY_SUPPLIER is
where is.INVSUP_INVID = i.INV_ID
and is.INVSUP_SUPPNUM = :suppnum
and i.INV_QTYONORDER <> 0)
>update INVENTORY
>set INVENTORY.INV_QTYONORDER = 0
>from INVENTORY
>left outer join INVENTORY_SUPPLIER
>on (INVENTORY.INV_ID = INVENTORY_SUPPLIER.INVSUP_INVID)
>where INVENTORY.INV_QTYONORDER <> 0
>and INVENTORY_SUPPLIER.INVSUP_SUPPNUM = 10