From: | William Alves Da Silva <william_silva(at)unochapeco(dot)edu(dot)br> |
---|---|
To: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>, Shaozhong SHI <shishaozhong(at)gmail(dot)com> |
Subject: | Re: select only 1 pair |
Date: | 2022-10-24 15:01:30 |
Message-ID: | 7f09c27c-c4df-4836-bd29-706ebc5eb154@Spark |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hello David,
Try this.
This is an exemple of your table.
SELECT *
FROM (VALUES (1, 2), (2, 1), (3, 4), (4, 1)) t (id1, id2)
id1 |id2 |
------+------+
1| 2|
2| 1|
3| 4|
4| 1|
I think that is what you need
SELECT DISTINCT LEAST(id1, id2) AS id1, GREATEST(id1, id2) AS id2
FROM (VALUES (1, 2), (2, 1), (3, 4), (4, 3)) t (id1, id2)
id1 |id2 |
------+------+
1| 2|
3| 4|
Regards,
William Alves
On 24 Oct 2022 11:44 -0300, Shaozhong SHI <shishaozhong(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Frank Streitzig | 2022-10-24 15:01:54 | Re: select only 1 pair |
Previous Message | Voillequin, Jean-Marc | 2022-10-24 14:59:56 | RE: select only 1 pair |