Re: Updating table with max from another table

From: "Bjoern Metzdorf" <bm(at)turtle-entertainment(dot)de>
To: <pgsql-general(at)postgresql(dot)org>
Cc: "Dan Winslow" <d(dot)winslow(at)cox(dot)net>
Subject: Re: Updating table with max from another table
Date: 2002-11-26 19:41:45
Message-ID: 000f01c29583$db2e6360$0564a8c0@toolteam.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> update a from b such that a.maxtype is set equal to the b.type whose val
> number is the highest for that matching id, that is, the result

How about:

update a set maxtype = (select type from b where b.id = a.id order by val
desc limit 1);

?

Regards,
Bjoern

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Luc Lachance 2002-11-26 19:41:47 Re: ALTER TRIGGER DISABLE/ENABLE
Previous Message Neil Conway 2002-11-26 19:12:03 Re: EXECUTE problems