Thread: update with select

update with select

From
"Cristóvão B. B. Dalla Costa"
Date:
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.


Re: update with select

From
Jean-Luc Lachance
Date:
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