Re: cartesian product

Поиск
Список
Период
Сортировка
От Luiz K. Matsumura
Тема Re: cartesian product
Дата
Msg-id 45D9E4C4.1080304@planit.com.br
обсуждение исходный текст
Ответ на cartesian product  ("Salman Tahir" <salmantahir1@gmail.com>)
Список pgsql-sql
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.



В списке pgsql-sql по дате отправления:

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: cartesian product
Следующее
От: "Phillip Smith"
Дата:
Сообщение: DISTINCT ON not working...?