With reference to How to use COALESCE with multiple rows and without preceding comma? ...
I have a similar scenario but with a small difference. I would be grateful if any expert could help me with it.
Data
area | city | state
1 | a | a
2 | a | a
3 | b | a
4 | b | a
1 | a | b
2 | a | b
3 | c | b
4 | c | b
Desired Results
Now I would like to retrieve the results as:
area | city | state
1,2,3,4 | a,b | a
1,2,3,4 | a,c | b
Retrieved Results
I tried myself with the above mentioned solution, but I am receiving the following result set:
area | city | state
1,2,3,4 | a,a,b,b | a
1,2,3,4 | a,a,c,c | b
I need city to be distinct.
I hope I have explained good enough?