RE: select only 1 pair

From: "Voillequin, Jean-Marc" <Jean-Marc(dot)Voillequin(at)moodys(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>, pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: RE: select only 1 pair
Date: 2022-10-24 14:59:56
Message-ID: MN2PR20MB2735EC8F53206F809521AA16BE2E9@MN2PR20MB2735.namprd20.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

select id1,id2 from your_table where id2>=id1
union
select id2,id1 from your_table where id2<id1;

should work

From: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Sent: Monday, October 24, 2022 4:44 PM
To: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: select only 1 pair

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 ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍ ‍
ZjQcmQRYFpfptBannerStart
This email originated from outside of Moody's
Do not click links or open attachments unless you recognize the sender and know the content is safe.
ZjQcmQRYFpfptBannerEnd
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

----------------------------------------------------------------------
Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message William Alves Da Silva 2022-10-24 15:01:30 Re: select only 1 pair
Previous Message 2022-10-24 14:51:26 AW: select only 1 pair