Re: select only 1 pair

From: Thomas Kellerer <shammat(at)gmx(dot)net>
To: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: select only 1 pair
Date: 2022-10-24 15:08:52
Message-ID: a4adc314-dbe1-e0c3-b9d9-84decd08c36a@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Steve Midgley 2022-10-24 15:57:01 Re: select only 1 pair
Previous Message Frank Streitzig 2022-10-24 15:01:54 Re: select only 1 pair