Re: select only 1 pair

Поиск
Список
Период
Сортировка
Искать
От
William Alves Da Silva
Тема
Re: select only 1 pair
Дата
Msg-id
7f09c27c-c4df-4836-bd29-706ebc5eb154@Spark
Ответ на
select only 1 pair (Shaozhong SHI)
Список
Дерево обсуждения
select only 1 pair Shaozhong SHI <shishaozhong@gmail.com>
AW: select only 1 pair Stöcker, Martin <Martin.Stoecker@etl-datenservice.de>
Re: select only 1 pair William Alves Da Silva <william_silva@unochapeco.edu.br>
Re: select only 1 pair Steve Midgley <science@misuse.org>
Re: select only 1 pair Thomas Kellerer <shammat@gmx.net>
RE: select only 1 pair "Voillequin, Jean-Marc" <Jean-Marc.Voillequin@moodys.com>
Re: select only 1 pair Frank Streitzig <fstreitzig@gmx.net>
Hello David,

Try this.

This is an exemple of your table.
SELECT * 
  FROM (VALUES (1, 2), (2, 1), (3, 4), (4, 1)) t (id1id2)
  
id1   |id2   |
------+------+
     1|     2|
     2|     1|
     3|     4|
     4|     1|      
     

I think that is what you need
SELECT DISTINCT LEAST(id1id2AS id1GREATEST(id1id2AS id2
  FROM (VALUES (1, 2), (2, 1), (3, 4), (4, 3)) t (id1id2)

id1   |id2   |
------+------+
     1|     2|
     3|     4|

Regards,


William Alves

On 24 Oct 2022 11:44 -0300, Shaozhong SHI <shishaozhong@gmail.com>, wrote:
There are pair ids.  Each pair is repeated.

id1   id2
1       2
2        1
3         4
4         3

How to only select 1 unique pair for each?

Regards,

David
В списке pgsql-sql по дате отправления
От: Voillequin, Jean-Marc
Дата:
Сообщение: RE: select only 1 pair
От: Frank Streitzig
Дата:
Сообщение: Re: select only 1 pair
FAQ