Re: more than one row returned by a subquery used as an - Mailing list pgsql-general

From Alban Hertroys
Subject Re: more than one row returned by a subquery used as an
Date
Msg-id 434FAB40.8070103@magproductions.nl
Whole thread Raw
In response to more than one row returned by a subquery used as an expression  (CSN <cool_screen_name90001@yahoo.com>)
List pgsql-general
CSN wrote:
> I'm trying to get this query to work:
>
> update sectors set companies =(select companies from
> industries where sector_id =sectors.id);

Try these instead:

update sectors
    set companies = industries.companies
   from industries
  where industries.sector_id =sectors.id;

update industries
    set companies = count(companies.id)
   from companies
  where industry_id = industries.id;

--
Alban Hertroys

pgsql-general by date:

Previous
From: "Rick Schumeyer"
Date:
Subject: problem converting from 8.0.4 to 8.1beta3: character encoding
Next
From: Bruce Momjian
Date:
Subject: Re: Postgres logs to syslog LOCAL0