To fetch the data from SQL and display it in comma separated, we need to use one SQL function for this.
SELECT STRING_AGG(column_name, ', ') AS concatenated_string
FROM table_name;
This function is useful to achieve this functionality.
How to use it?
SELECT string_agg(column_name, ',')
FROM DEPT;
Output
1,2,3,4 - data will display like this.
Note. This SQL function is available in a higher version.