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 E6564DB12E for ; Thu, 27 Oct 2005 15:00:44 -0300 (ADT) 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 10017-01 for ; Thu, 27 Oct 2005 18:00:41 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by svr1.postgresql.org (Postfix) with ESMTP id 5AADBDB121 for ; Thu, 27 Oct 2005 15:00:41 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 71so174575wra for ; Thu, 27 Oct 2005 11:00:42 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=Mzzgh9ox7snl9xrPw0yipHIhdLe3X/1vCzjFNOLMMwgNaSXiKIUcbIi+Ul9OEv9e2UnxQ8NWChg9CoC5diw09CQlBOjL09VGWb6RRZeyK62SBli1S8kXzrb6ZFyTTl4zM8Cc6iTF47UR4OaRarHJZr6BvEHObBfsSFvd8ccJEyA= Received: by 10.54.107.8 with SMTP id f8mr1109616wrc; Thu, 27 Oct 2005 11:00:41 -0700 (PDT) Received: by 10.54.99.1 with HTTP; Thu, 27 Oct 2005 11:00:41 -0700 (PDT) Message-ID: <506ca6630510271100y367e1fb2hfb05f5ecaae043a3@mail.gmail.com> Date: Thu, 27 Oct 2005 14:00:41 -0400 From: Abhishek To: pgsql-sql@postgresql.org Subject: combining records from a single table and presenting them as one record MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5244_26814942.1130436041950" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[HTML_MESSAGE=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200510/374 X-Sequence-Number: 23227 ------=_Part_5244_26814942.1130436041950 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi Everyone I have a table "TABLE1" which has ---------------------------------------------------- Callguid | digits | type ---------------------------------------------------- xxxx 123 'a' xxxx 345 'b' xxxx 678 'c' type can have only 'a', 'b' or 'c' as its value. I am tryng to write a query which returns me a record like this ---------------------------------------------------------------------------= ---------------------------- CallGuid | a type digits | b type digits | c type digits ---------------------------------------------------------------------------= ---------------------------- xxxx 123 345 678 I do the query as this: select callguid , ( select digits from TABEL1 where type=3D'a' ), ( select digits from TABEL1 where type=3D'b' ), ( select digits from TABEL1 where type=3D'c' ) from TABLE1; result: ---------------------------------------------------------------------------= ---------------------------- CallGuid | a type digits | b type digits | c type digits ---------------------------------------------------------------------------= ---------------------------- xxxx 123 345 678 xxxx 123 345 678 xxxx 123 345 678 Note that I get the records which i wanted, but I get them duplicated. If = I use 'distinct' keyword I get the desired result with no duplication. But 'distinct' seems to be too expensive. Is there any better way I can do this without compromising the performance ? Your suggestions and input are very appreciated Thanks AJ -- Abhishek Jain ------=_Part_5244_26814942.1130436041950 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi Everyone
 
I have a table "TABLE1"  which has
----------------------------------------------------
Callguid      |     =   digits     |      type<= /div>
----------------------------------------------------
xxxx           =         123     = ;          'a'
xxxx           =         345    =            'b'
xxxx           =         678     = ;          'c'
 
type can have only 'a', 'b' or 'c' as its value.
I am tryng to write a query which returns me a record like this
 
----------------------------------------------------------------------= ---------------------------------
CallGuid      |     =   a type digits       |   = ;  b type digits     |     c t= ype digits
----------------------------------------------------------------------= ---------------------------------
xxxx           =          123    = ;            &n= bsp;        345    &= nbsp;           &nbs= p;      678
 
 
I do the query as this:
 
select callguid , ( select digits from TABEL1 where type=3D'a' ), ( se= lect digits from TABEL1 where type=3D'b' ), ( select digits from TABEL1 whe= re type=3D'c' ) from TABLE1; 
 
result:
----------------------------------------------------------------------= ---------------------------------
CallGuid      |     =   a type digits       |   = ;  b type digits     |     c t= ype digits
----------------------------------------------------------------------= ---------------------------------
xxxx           =          123    = ;            &n= bsp;        345    &= nbsp;           &nbs= p;      678
xxxx           =          123    = ;            &n= bsp;        345    &= nbsp;           &nbs= p;      678
xxxx           =          123    = ;            &n= bsp;        345    &= nbsp;           &nbs= p;      678
 
Note that I get the records which i wanted, but I get them duplicated.= If I use 'distinct' keyword I get the desired result with no duplication. = But 'distinct' seems to be too expensive.
 
Is there any better way I can do this without compromising the perform= ance ?
 
Your suggestions and input are very appreciated
 
Thanks
AJ
 


--
Abhishek Jain
 
------=_Part_5244_26814942.1130436041950--