Subject | Re: [firebird-support] Re: update from 2 tables |
---|---|
Author | Svein Erling Tysvaer |
Post date | 2006-06-23T10:19:39Z |
cbll_lam wrote:
a record in B where B.Y has the same value as A.X, then it knows that it
should update A.
two different aliases because that's what I normally do to not even have
to think about ambiguity (Firebird has become stricter and stricter in
this respect, and many queries that used to give you unexpected results,
now causes errors).
huge, then the query will be the fastest, if b is small and a is huge
(probably the most common for this kind of queries), then the stored
procedure will be faster.
Set
> Svein Erling Tysvaerwrote:What the query does is to do a check for every record in A. If it finds
>
>> update TableA a
>> set a.p=(select b.q from TableB b where b.y=a.x)
>> where exists(select * from TableB c where c.y=a.x)
>
> Thank you all! I test it works although I still do not understand why
> it work, because I'm not good in working with subquery.
a record in B where B.Y has the same value as A.X, then it knows that it
should update A.
> Will it fail if 2 different alias not set for tableB?Either you get an error message or it works (in this case). I just used
> eg.
> update a
> set a.p=(select b.q from b where b.y=a.x)
> where exists(select 1 from b where b.y=a.x)
two different aliases because that's what I normally do to not even have
to think about ambiguity (Firebird has become stricter and stricter in
this respect, and many queries that used to give you unexpected results,
now causes errors).
> Which method, this and the SP suggested by Adam, is faster? I meantI think that depends on the size of both a and b. If a is small and b is
> execution speed for larger table.
huge, then the query will be the fastest, if b is small and a is huge
(probably the most common for this kind of queries), then the stored
procedure will be faster.
Set