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 CC7DF30DEB8 for ; Fri, 20 Jun 2003 06:07:35 +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 67631-04 for ; Fri, 20 Jun 2003 03:07:25 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id EE60E30DDED for ; Fri, 20 Jun 2003 03:07:24 -0300 (ADT) Received: from klaster.net (tv126.internetdsl.tpnet.pl [80.55.125.126]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 71F892B5B7; Fri, 20 Jun 2003 08:06:58 +0200 (CEST) Message-ID: <3EF2A496.40505@klaster.net> Date: Fri, 20 Jun 2003 08:07:18 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.4b) Gecko/20030507 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: =?ISO-8859-2?Q?Egy=FCd_Csaba?= Cc: pgsql-sql@postgresql.org Subject: Re: Getting one row for each subquery row...? References: <007901c336ea$9cee0e80$230a0a0a@compaq> In-Reply-To: <007901c336ea$9cee0e80$230a0a0a@compaq> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Archive-Number: 200306/232 X-Sequence-Number: 13990 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 > Sure, use "limit 1" in a subquery. "limit" and "offset" are well described in Postgresql documentation. Regards, Tomasz Myrta