Re: select only 1 pair - Mailing list pgsql-sql

From Thomas Kellerer
Subject Re: select only 1 pair
Date
Msg-id a4adc314-dbe1-e0c3-b9d9-84decd08c36a@gmx.net
Whole thread Raw
In response to select only 1 pair  (Shaozhong SHI <shishaozhong@gmail.com>)
List pgsql-sql
Shaozhong SHI schrieb am 24.10.2022 um 16:44:
> 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?

select distinct least(id1,id2), greatest(id1,id2)
from the_table



pgsql-sql by date:

Previous
From: Frank Streitzig
Date:
Subject: Re: select only 1 pair
Next
From: Steve Midgley
Date:
Subject: Re: select only 1 pair