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