I have a table table1
like:
col1 col2
A1 A2
A1 B1
A1 B2
A2 A1
A2 B1
A2 B2
B1 A1
B1 A2
B1 B2
B2 A1
B2 A2
B2 B1
I need to concat col1
and col2
such a way that it should be sorted first.
Expected result:
col1 col2 ConcatResult
A1 A2 A1-A2
A1 B1 A1-B1
A1 B2 A1-B2
A2 A1 A1-A2
A2 B1 A2-B1
A2 B2 A2-B2
B1 A1 A1-B1
B1 A2 A2-B1
B1 B2 B1-B2
B2 A1 A1-B2
B2 A2 A2-B2
B2 B1 B1-B2
One more requirement: if possible, I would like to select the distinct from ConcatResult
column.
Best Answer
You can do
Output:
To get distinct values from concatenated result
Output:
Here is SQLFiddle demo