X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id BCDA83100F4 for ; Fri, 27 Jun 2003 14:05:34 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 78567-08 for ; Fri, 27 Jun 2003 11:05:24 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id CA4693100D6 for ; Fri, 27 Jun 2003 11:05:23 -0300 (ADT) Received: (qmail 15376 invoked by uid 500); 27 Jun 2003 14:08:54 -0000 Date: Fri, 27 Jun 2003 09:08:54 -0500 From: Bruno Wolff III To: =?iso-8859-1?Q?Egy=FCd?= Csaba Cc: pgsql-sql@postgresql.org Subject: Re: Getting all rows even if not a member of any groups Message-ID: <20030627140854.GA15269@wolff.to> Mail-Followup-To: =?iso-8859-1?Q?Egy=FCd?= Csaba , pgsql-sql@postgresql.org References: <11362.1056313692@www59.gmx.net> <00bd01c33c9d$1b584e90$230a0a0a@compaq> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <00bd01c33c9d$1b584e90$230a0a0a@compaq> User-Agent: Mutt/1.5.4i X-Archive-Number: 200306/312 X-Sequence-Number: 14070 On Fri, Jun 27, 2003 at 13:13:07 +0200, Együd Csaba 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;