From: Bruno Wolff III <bruno@wolff.to>
To: Együd Csaba <csegyud@freemail.hu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Getting all rows even if not a member of any groups
Date: Fri, 27 Jun 2003 09:08:54 -0500
Message-ID: <20030627140854.GA15269@wolff.to> (raw)
In-Reply-To: <00bd01c33c9d$1b584e90$230a0a0a@compaq>
References: <11362.1056313692@www59.gmx.net>
<00bd01c33c9d$1b584e90$230a0a0a@compaq>
On Fri, Jun 27, 2003 at 13:13:07 +0200,
Együd Csaba <csegyud@freemail.hu> wrote:
> Hi,
Please don't reply to messages to start a new thread.
> I have a product table identified by its id field. There is a productgroups
> table with productisd, productgroupid fields. And I have a prod_in_pgr
> (productid, productgroupid) table which describes the membership of
> productgroups. Each product can be a member of zero or more productgroups,
> but one productgroup can contain a product only once.
>
> I would like to list the following information:
> productgroupid | productid | ... some other prouduct info | ...
>
> I need all the products even if it is not a member in any productgroups. I
> need these information ordered by productgroup and then productid.
> --------------------------------
> An example:
>
> select t_productgroups.name as pgroup,
> t_products.id as productid
> from t_products
> join t_prod_in_pgr on (t_products.id=productid)
> join t_productgroups on (t_productgroups.id = t_prod_in_pgr.productgroupid)
> order by pgroup, productid;
I think you want something like:
select t_productgroups.name as pgroup,
t_products.id as productid
from t_products
left join (t_prod_in_pgr
join t_productgroups on (t_productgroups.id = t_prod_in_pgr.productgroupid))
on (t_products.id=productid)
order by pgroup, productid;
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: bruno@wolff.to, csegyud@freemail.hu
Subject: Re: Getting all rows even if not a member of any groups
In-Reply-To: <20030627140854.GA15269@wolff.to>
* 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