X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D5B3DD6F45 for ; Tue, 8 Nov 2005 12:17:19 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 34222-10 for ; Tue, 8 Nov 2005 16:17:18 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 67464D6855 for ; Tue, 8 Nov 2005 12:17:17 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id E471931059; Tue, 8 Nov 2005 17:17:15 +0100 (MET) From: "codeWarrior" X-Newsgroups: pgsql.sql Subject: Re: Returning rows as columns Date: Tue, 8 Nov 2005 08:19:58 -0800 Organization: Hub.Org Networking Services Lines: 46 Message-ID: References: <1131446104.767844.57070@f14g2000cwb.googlegroups.com> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Original To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.29 required=5 tests=[AWL=0.741, FORGED_HOTMAIL_RCVD2=0.549] X-Spam-Score: 1.29 X-Spam-Level: * X-Archive-Number: 200511/68 X-Sequence-Number: 23319 You're looking for a technique generally referred to as a "pivot table" which is really a non-normalized or aggregate view of relational data.... You'll find plenty of examples if you Google "pivot table". "Paul" wrote in message news:1131446104.767844.57070@f14g2000cwb.googlegroups.com... > Hi, > > I'm looking for a way to return rows as columns. My problem is the > following. I have three tables: > suppliers,products and productprices. A supplier and a product make a > productprice. A certain product may have an x number of suppliers and > prices. > > Now I have the following query: > select > products.int_artnr,products.str_name,suppliers.str_naam,productprices.flt_price > from products,productprices,suppliers > WHERE products.int_artnr = productprices.int_artnr > AND suppliers.int_crednr=productprices.int_crednr > ORDER BY int_artnr > > This gives me a result but not the one I wanted. I want to have a > dataset that returns the supplierprice and suppliername as a column > behind every product for all suppliers. So you get an x number of > columns. > > Example: > > Number Name Suppl1 Price1 Suppl2 Price2 > > 1 Beer 10 cases Heineken 3.33 Amstel 1.55 > 2 Beer 2 cases Heikenen 1.22 > > > Could someone please give me some pointers if this is achievable and if > yes, how I should do this? > > Thx, > > Paul >