Subject Re: [firebird-support] Update on joined tables
Author Helen Borrie
At 05:44 AM 12/07/2005 +0000, you wrote:
>Hi everyone,
>
>Is there a way to update a table A with values from another table B
>when the two tables share same field value?
>I've tried this, but it doesn't work:
>
>update tableA
>inner join tableB on tableA.field1 = tableB.field1
>set tableA.field2 = tableB.field2

Correct, it's not a valid statement. You'll need a correlated subquery:

update tableA a
set a.field2 =
(select b.field2 from TableB b
where b.field1 = a.field1)

Watch out, though. This will except with "Multiple rows in singleton
select" if the subquery doesn't return a scalar result, i.e. there is more
than one row in b where b.field1 = a.field1. (The same limitation of logic
potentially exists in your posited join syntax, too...)

./heLen