X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 219C647592C for ; Tue, 1 Apr 2003 19:17:43 -0500 (EST) Received: from pimout2-ext.prodigy.net (pimout2-ext.prodigy.net [207.115.63.101]) by postgresql.org (Postfix) with ESMTP id A2CE44758C9 for ; Tue, 1 Apr 2003 19:17:35 -0500 (EST) Received: from theplague (adsl-66-126-110-160.dsl.lsan03.pacbell.net [66.126.110.160]) by pimout2-ext.prodigy.net (8.12.3 patch/8.12.3) with ESMTP id h320HSqD252536 for ; Tue, 1 Apr 2003 19:17:36 -0500 From: "James Taylor" To: Subject: Rows as Columns Date: Tue, 1 Apr 2003 16:17:39 -0800 Message-ID: <002801c2f8ad$4888c9f0$4500a8c0@theplague> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Spam-Status: No, hits=-0.4 required=5.0 tests=BAYES_30,RCVD_IN_NJABL version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/14 X-Sequence-Number: 12715 Hi everyone, I just joined this list a few days ago... Now, I have a question, and I'm not even sure if this is possible without having to make numerous statements. Say I have two tables with the following columns and this data: types: id | name ----------------- 1 | first_name 2 | last_name 3 | phone_number data: id | data | t_key | cust_id --------------------------------- 1 | Sam | 1 | 1 2 | Smith | 2 | 1 3 | 555-1212 | 3 | 1 4 | John | 1 | 2 Types basically describes what the column type is. t_key references the type, cust_id is the user id. i'd want to do something like "select t.name, d.data from types t, data d where d.cust_id = 1" This would return something like: name | data ------------------------ first_name | Sam last_name | Smith phone_number | 555-1212 Well, I need it to somehow return that data in this format: first_name | last_name | phone_number ---------------------------------------- Sam | Smith | 555-1212 The information in Types is not static, so I can't declare the col names based on what you see here. Any suggestions on this one?