Re: select only 1 pair

Поиск
Список
Период
Сортировка
От Frank Streitzig
Тема Re: select only 1 pair
Дата
Msg-id Y1ao4uH2OG8d5N96@frastr-dev
обсуждение исходный текст
Ответ на select only 1 pair  (Shaozhong SHI <shishaozhong@gmail.com>)
Список pgsql-sql
Am Mon, Oct 24, 2022 at 03:44:03PM +0100 schrieb Shaozhong SHI:
> 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

Hello,

if just 2 id's then sort with min and max comparing.
Example:

with data (id1, id2) as (
    values (1,2), (2,1), (3,4), (4,3)
)
select case when id1 <= id2 then id1 else id2 end as idmin
       , case when not id1 <= id2 then id1 else id2 end as idmin
    from data
    group by 1, 2
;

Best regards,
Frank



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

Предыдущее
От: William Alves Da Silva
Дата:
Сообщение: Re: select only 1 pair
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: select only 1 pair