From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Együd Csaba <csegyud(at)freemail(dot)hu> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Getting all rows even if not a member of any groups |
Date: | 2003-06-27 14:08:54 |
Message-ID: | 20030627140854.GA15269@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Fri, Jun 27, 2003 at 13:13:07 +0200,
Együd Csaba <csegyud(at)freemail(dot)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;
From | Date | Subject | |
---|---|---|---|
Next Message | Együd Csaba | 2003-06-27 14:18:10 | Re: Getting all rows even if not a member of any groups |
Previous Message | Együd Csaba | 2003-06-27 14:07:01 | Re: Postgres - Delphi Application |