I have a table A with following data:
A:
colA colB
a x
b x
c y
d y
e z
f z
I want the output as:
colA colA_1
a b
c d
e f
I.e. I want to group the data based on colB and fetch the values from colA. I know that the same value will appear exactly twice in colB.
What I am trying to do is:
SELECT a1.colA, a2.colA
FROM A a1
JOIN A a2
ON a1.colA != a2.colA and a1.colB=a2.colB;
But this gives the output as:
colA colA_1
a b
b a
c d
d c
e f
f e
How can I fix this to get the desired output?