Select distinct and non-distinct column values
Do you want list_agg
?
select colA, colB, list_agg(distinct colC, ','), list_agg(distinct colD, ',')from Table1Group by ColA, ColB
If any arbitrary value would do for ColC and colD, you can use min()
:
select colA, colB, min(colC), min(colD)from Table1Group by ColA, ColB
The DISTINCT applies to all values you are selecting, not just to some columns. In your case it will apply to all: colA, colB, colC, colD. It is impossible to select all columns and make some distinct and some not. The only way to do this shown in Gordon's example, this is the only valid example and answer.