Subject Re: [ib-support] Searching for last record
Author Andrew Guts
lele@... wrote:

> >> 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))
> >>
> >>
> >>
> AG> By the way it's a surprise:
>
> AG> "Error: multiple rows in singleton select"
>
> AG> So "max()" could return multiple rows?. How nice.
>
>But that's not what probably happened! May be you have more LOCATIONs in
>TRANSFERS with the same ID...
>
Sure, but x.id is a primary key. And 'max(cx.id)' as an aggregate
function should return only one value or NULL.

>
>BTW, maybe you can get better results with something like
>
>UPDATE catalogue c
>SET c.last_location = (SELECT FIRST t.location
> FROM transfers t
> WHERE t.catalog_id = c.id
> ORDER BY id DESC)
>
>Not actually tried, just guessing if `FIRST' is good in this
>situation.
>
No way, thanks. Excuse me please.

Andrew