Re: Getting all rows even if not a member of any groups
От | Bruno Wolff III |
---|---|
Тема | Re: Getting all rows even if not a member of any groups |
Дата | |
Msg-id | 20030627140854.GA15269@wolff.to обсуждение исходный текст |
Ответ на | Getting all rows even if not a member of any groups (Együd Csaba <csegyud@freemail.hu>) |
Список | pgsql-sql |
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;
В списке pgsql-sql по дате отправления: