pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Myrta <jasiek@klaster.net>
To: Együd Csaba <csegyud@freemail.hu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Getting one row for each subquery row...?
Date: Fri, 20 Jun 2003 08:11:58 +0200
Message-ID: <3EF2A5AE.1030006@klaster.net> (raw)
In-Reply-To: <007901c336ea$9cee0e80$230a0a0a@compaq>
References: <007901c336ea$9cee0e80$230a0a0a@compaq>

Dnia 2003-06-20 07:12, Użytkownik Együd Csaba napisał:

> Hi All,
>  here are my three tables. I wold like to list them in the following way: I
>  need all the columns from t_stockchanges, and one field for the
> productgroup
>  the t_stockchanges.productid belongs to.
> 
>  But one product can belong to many groups, so i would need one row for each
>  group for each product.
> 
>  My bad query is:
>  ------------------------
>  DB=# select t_stockchanges.productid, (select name from t_productgroups
>  where id=(select productgroupid from t_prod_in_pgr where
>  productid=t_stockchanges.productid)) as pgroup from t_stockchanges;
>  ERROR:  More than one tuple returned by a subselect used as an expression.
>  DB=#
>  ---------------
>  Yes, this is absolutelly true, but I would like postgres to give me all the
>  tuples found. How can I ask him to do so?
> 
>  Thank you,
>  -- Csaba
Sorry, if you want all combination of grups and products, you need to rewrite 
your query:

select
  t_stockchanges.productid,
  t_productgroups.name as pgroup
from
  t_stockchanges
  join t_prod_in using (productid)
  join t_productgroups on (id=productgroupid)

or something like this.

Tomasz





view thread (4+ messages)  latest in thread

Message-ID: <3EF2A5AE.1030006@klaster.net>
Permalink:  ../3EF2A5AE.1030006@klaster.net/
Also on:    postgresql.org/message-id/3EF2A5AE.1030006@klaster.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jasiek@klaster.net, csegyud@freemail.hu
  Subject: Re: Getting one row for each subquery row...?
  In-Reply-To: <3EF2A5AE.1030006@klaster.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox