Re: update with select

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: " Cristóvão B(dot) B(dot) Dalla Costa" <cbraga(at)bsi(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: update with select
Date: 2003-01-09 23:08:31
Message-ID: 3E1E00EF.1444EC0@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Try:

UPDATE product SET price_min = ss.min_price, price_max = ss.max_price
from ( select min( price) as min_price, max( price) as max_price
FROM subproduct WHERE subproduct.product = $ID) as ss
WHERE id = $ID;

"Cristóvão B. B. Dalla Costa" wrote:
>
> Hi,
>
> Is it possible to rewrite this query to use a single SELECT?
>
> UPDATE product SET
> price_min = (SELECT min (price) FROM subproduct WHERE subproduct.product
> = $ID),
> price_max = (SELECT max (price) FROM subproduct WHERE subproduct.product
> = $ID)
> WHERE id = $ID
>
> Thanks.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Feite Brekeveld 2003-01-09 23:20:39 unsubscribe
Previous Message Brian Hirt 2003-01-09 22:13:56 Re: Version Problems on Mac OS X.2 Jaguar