Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 3A0EE9FB9E2 for ; Mon, 19 Feb 2007 14:41:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 05441-08 for ; Mon, 19 Feb 2007 14:41:14 -0400 (AST) X-Greylist: delayed 00:44:49.15675 by SQLgrey-1.7.4 Received: from andromeda1.neonex.com.br (dns3.neonex.com.br [201.28.22.10]) by postgresql.org (Postfix) with ESMTP id 6FF789FB6A6 for ; Mon, 19 Feb 2007 14:41:15 -0400 (AST) Received: from [200.206.25.4] (helo=[127.0.0.1]) by andromeda1.neonex.com.br with esmtpa (Exim 4.63) (envelope-from ) id 1HJCkY-0006T4-4T; Mon, 19 Feb 2007 14:56:30 -0300 Message-ID: <45D9E4C4.1080304@planit.com.br> Date: Mon, 19 Feb 2007 15:56:20 -0200 From: "Luiz K. Matsumura" Organization: Plan IT Tecnologia =?ISO-8859-1?Q?Inform=E1tica_Ltda=2E?= User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Salman Tahir CC: pgsql-sql@postgresql.org References: <2049e51a0702190858n6932461dgc294d05b035aad53@mail.gmail.com> In-Reply-To: <2049e51a0702190858n6932461dgc294d05b035aad53@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 000714-4, 02/19/2007), Outbound message X-Antivirus-Status: Clean X-SA-Exim-Connect-IP: 200.206.25.4 X-SA-Exim-Rcpt-To: salmantahir1@gmail.com, pgsql-sql@postgresql.org Subject: Re: cartesian product X-SA-Exim-Version: 4.2.1 (built Mon, 27 Mar 2006 13:42:28 +0200) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200702/203 X-Sequence-Number: 27537 Hi, Salman Maybe this isn't so much elegant, but works: SELECT p1.sequence as sequence1, p2.sequence as sequence2 FROM potential_pairs p1, potential_pairs p2 WHERE p1.sequence <= p2.sequence Hope this helps Salman Tahir wrote: > Hi, > > I have a query regarding an SQL statement I'm trying to execute. I > have the following table: > > sequence > -------------+ > AK > AKCMK > CMKA > > I execute the following statement (Cartesian product): > > SELECT p1.sequence as sequence1, p2.sequence as sequence2 > FROM potential_pairs p1, potential_pairs p2 > > which gives me: > > sequence1 | sequence2 > ----------------+-------------- > AK | AK > AK | AKCMK > AK | CMKA > AKCMK | AK > AKCMK | AKCMK > AKCMK | CMKA > CMKA | AK > CMKA | AKCMK > CMKA | CMKA > (9 rows) > > I want to eliminate duplicates and by duplicate I mean a tuple such as > {AK, CMKA} should be regarded as the same as {CMKA, AK}. So I would > like the following result: > > sequence1 | sequence2 > ----------------+-------------- > AK | AK > AK | AKCMK > AK | CMKA > AKCMK | AKCMK > AKCMK | CMKA > CMKA | CMKA > > Any help would be appreciated. > > - Salman > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > > -- Luiz K. Matsumura Plan IT Tecnologia Informática Ltda.