sql - Filter rows that have the same data in different columns -
this question has answer here:
i have data looks this:
| b 97 |556 257|803 803|257 257|323 556|97
i'm trying figure out best way filter results such removes duplicate rows. example shows row 257|803 , not 803|257. best way this?
select * t x x.a < x.b or not exists ( select * t y y.a = x.b , y.b = x.a );
the truth table strange condition:
| b | (a<b) | (not exists) | (a<b or not exists) ---+----+-------+--------------+---------------------- 97 |556 | true | false | true 257|803 | true | false | true 803|257 | false | false | false 257|323 | true | true | true 556|97 | false | false | false
result:
| b -----+----- 97 | 556 257 | 803 257 | 323 (3 rows)
Comments
Post a Comment