Subject Re: [ib-support] Searching for last record
Author Arno Brinkman
Hi,

> I'm trying to update catalogue.last_location according last record of
> transfers:
>
> update catalogue
> set last_location =
> (select location from transfers x where x.catalog_id = catalogue.id
> and x.id =
> (select max(id) from transfers cx where cx.catalog_id = x.catalog_id))
>
> that update hangs. I've discovered that above subselects use natural
join...
> Pure select is too heavy, but it works fine if looks like :
>
> select x.location from tranfers x join transfers cx on x.catalog_id =
> cx.catalog_id
> group by x.location
> having x.id = max(cx.id)
>
> Is it better way to do such updates ?

Maybe you did mean this :

update catalogue
set last_location =
(select x.location from transfers x where x.id =
(select max(cx.id) from transfers cx where cx.catalog_id = id))

Regards,
Arno