My dear colleague @Lupp is absolutely right - there is no easy way to do what you have in mind. The fact is that Calc does not yet have a UNIQUE() function. You will have to use the helper columns.

Enter the formula `=TRIM(A2)`

in cell **E2**

Now in cell **F2**, enter a slightly more complex formula - `=IF(TRIM(B2)=E2;"";TRIM(B2))`

Cell **G2** will contain an even more complex formula - `=IF(COUNTIF(E2:F2;TRIM(C2));"";TRIM(C2))`

Now go back to cell **D2** and enter `=TEXTJOIN(", ";1;E2:G2)`

(This is the same function that was mentioned in the comments, but it will work not with source data, but with the results of calculations in auxiliary columns.)

Stretch the cells with formulas to the end of the data, replace the formulas in column D with their values (copy and paste special or Data-Text to Columns), delete the auxiliary columns.