Subject Re: [ib-support] Searching for last record
Author lele@seldati.it
>>>>> On Tue, 18 Jun 2002 16:13:14 +0300, Andrew Guts <andr@...> said:

AG> Andrew Guts 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...

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.

ciao, lele.
--
nickname: Lele Gaifax | Quando vivro' di quello che ho pensato ieri
real: Emanuele Gaifas | comincero' ad aver paura di chi mi copia.
email: lele@... | -- Fortunato Depero, 1929.