cartesian product - Mailing list pgsql-sql

From Salman Tahir
Subject cartesian product
Date
Msg-id 2049e51a0702190858n6932461dgc294d05b035aad53@mail.gmail.com
Whole thread Raw
Responses Re: cartesian product  (Scott Marlowe <smarlowe@g2switchworks.com>)
Re: cartesian product  (Scott Marlowe <smarlowe@g2switchworks.com>)
Re: cartesian product  ("Luiz K. Matsumura" <luiz@planit.com.br>)
List pgsql-sql
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    |
AKCMKAKCMK    | 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    |
CMKACMKA      | CMKA
 

Any help would be appreciated.

- Salman


pgsql-sql by date:

Previous
From: "Bart Degryse"
Date:
Subject: Re: Uppercase and Lowercase
Next
From: Scott Marlowe
Date:
Subject: Re: cartesian product