I have a table in my database with multiple columns, and I want to select distinct values from these columns and concatenate the results into a single string. How can I achieve this in a single SQL query?
ID COL1 COL2 COL3
1 P1 d1 V1
2 P1 d2 V1
3 P3 d1 V1
4 P3 d2 V1
5 P4 d1 V1
6 P4 d2 V1
Expected result :
P1;P3;P4;V1;d1;d2
In Oracle 11g, you'll need to take several steps:
In higher versions - which support
distinctwithinlistagg- things get simpler:or even