I’m trying to select two distinct numbers id1 and id2 from the following table:
tb_table1(
bigint id1
bigint id2
bigint userid)
if I do
select distinct id1, id2 from tb_table1
I’ll get, for example, two rows, (111, 222) and (222,111).
I only want one of those rows since I don’t care which column, id1, or id2 that the result gets returned in. Basically, I want distinct pairs where order doesn’t matter.
Thoughts? Thanks in advance.
It would be remiss of me to not point out that this suggests your table is not quite as normalized as it should be – what will you do when users acquire a third id? But anyway.
Using the fact that
UNION(as opposed toUNION ALL) will automatically de-duplicate, you could do