Subject Re: [firebird-support] SQL Update statement question in Firebird 1.5
Author Svein Erling Tysvaer
I'd try

update T1
set T1.Num1 = T1.Num1+(select sum(T2.Num2) from T2
where T1.Key1 = T2.Key2)
where exists(select * from T2 where T1.Key1 = T2.Key2)

HTH,
Set

jft1308 wrote:
> Just moved over to the Firebird SQL camp from the Microsoft SQL
> camp ... so far so good!
>
> I would like advice please on how to do an update to a table where
> the update statement involves a join.
> Say table T1 has 2 integer columns (Key1 and Num1) and table T2
> similarly has 2 integer columns (Key2 and Num2).
> Table T1:
> Key1 Num1
> 1 7000
> Table T2:
> Key2 Num2
> 1 654
> and you wanted to update T1.Num1 to be the sum of the 2 number
> fields, ie 7,654.
>
> In MS you would write:
> update T1
> set T1.Num1 = T1.Num1 + T2.Num2
> from T1, T2
> where T1.Key1 = T2.Key2;
>
> How do achieve the same result in Firebird 1.5?
> Thanks
> John