Subject Re: subselect in subselect problem?
Author Alexander V.Nevsky
--- In firebird-support@yahoogroups.com, "johnsparrowuk"
<jsparrow@e...> wrote:
> Is this a known bug?
>
> for select id,something from wtreestore into :id, :something do
> begin
> update demo set something = (select something from demo where
> id = (select max(id) from demo where id < :id))
> where id = :id;
> end
>
> Doesn't change anything

Yes and no. You have 2 mistakes here - ambiguity and usage of the
same parameter in different levels of nesteness (not sure such a word
exists but hope you understand me :) ). First is your bug, second
(IMO) - FB. Change it for

for select id,something from wtreestore into :id, :something do
begin
update demo D1 set D1.something =
(select D2.something from demo D2 where
D2.id =
(select max(D3.id) from demo D3 where D3.id < D1.id)
)
where D1.id = :id;
end

I think more effective it will be if you'll decrease nesteness

for select id,something from wtreestore into :id, :something do
begin
update demo D1 set D1.something =
(select first 1 D2.something from demo D2 where
D2.id < D1.id order by id desc)
)
where D1.id = :id;
end

but I think too most effective will be your variant with separated
queries.

Best regards,
Alexander.