Question: I am having below dummy table

```
select * from (
select 'A' as col1, 'B' as col2 from dual 
union
select 'B' as col1, 'A' as col2 from dual 
union
select 'A' as col1, 'C' as col2 from dual 
union
select 'C' as col1, 'A' as col2 from dual 
union
select 'A' as col1, 'D' as col2 from dual 
)a

```

which will give output as below

```
col1 col2
A   B
A   C
A   D
B   A
C   A

```

I wants to find the distinct values from that table like below

```
col1 col2
A    B
A    C
A    D

```

first row can be A B or B A same as second can be A C or C A

Is it possible??
We got the solution for above problem which is below

```
select distinct least(col1, col2), greatest(col1, col2)
from the_table;

```

but if there is more than 2 column, then i wouldn't work

Let us assume the below scenario

Input

```
 col1 col2 col3
    A   B   E
    A   C   E
    A   D   E
    B   A   F
    C   A   E

```

Output 

```
 col1 col2 col3
    A   B   E
    A   D   E
    B   A   F
    C   A   E

```

then what would be the possible solution ?

Answer: 
The following will work for Oracle and Postgres:

```
select distinct least(col1, col2), greatest(col1, col2)
from the_table;

```

Online example: <http://rextester.com/BZXC69735>
```
select col1, col2 from t where col1 <= col2
union
select col2, col1 from t where col1 > col2

```