I am trying to write two strings from selecting value from a column on multiple rows. I am getting a string back but the result is not correct, the string that is returned has repeated the specialism_name and qualification_name is being repeated as many times as there are qualifications for the worker. What do I need to do to adjust this SQL statement to make it write the names just once. I was thinking DISTINCT may work.
string_agg(specialism_name, ', ' ORDER BY sp.specialism_name ASC) as worker_specialisms,
string_agg(qualification_name, ', ' order by q.qualification_name asc) as worker_qualifications
from worker w
inner join users u using (worker_id)
inner join occupation o using (occupation_id)
inner join worker_specialism ws using (worker_id)
inner join specialism sp on ws.specialism_id = sp.specialism_id
inner join worker_qualification wq using (worker_id)
inner join qualification q on wq.qualification_id = q.qualification_id
where 1 = 1 GROUP BY w.worker_id, u.user_id, o.occupation_id ORDER BY first_name ASC