Re: Updating with a subselect - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Updating with a subselect
Date
Msg-id 20080423065541.S588@megazone.bigpanda.com
Whole thread Raw
In response to Updating with a subselect  ("Leandro Casadei" <mateamargo@gmail.com>)
Responses Re: Updating with a subselect  ("Leandro Casadei" <mateamargo@gmail.com>)
List pgsql-general
On Tue, 22 Apr 2008, Leandro Casadei wrote:

> Hi, I need to update a field from a table based in a count.
>
> This is the query:
>
>
> update    shops
> set    itemsqty =
>     (
>     select     count(*)
>     from     items i1
>     join      shops s1 on i1.shopid = s1.shopid
>     where   s1.shopid = s0.shopid
>     )
> from     shops s0

I think you'll actually want something simpler. The following might do
what you want.

update shops
set    itemsqty =
    (
    select     count(*)
    from     items i1
    where   i1.shopid = shops.shopid
    )

pgsql-general by date:

Previous
From: "Kerri Reno"
Date:
Subject: Re: FW: Re: create temp in function
Next
From: "Albe Laurenz"
Date:
Subject: Re: Deny creation of tables for a user