I have 5 tables, and i need select some columns from them. And some of tables have one to many relationship. And for this situations i use string_agg
I tried string_agg(cause, ', '), but after that i have error that i need group by all columns or be used in an aggregate function. Also i tried as there
SELECT p.id as person_id,
p.name as name,
p.surname as surname,
gr.registration_number as registry_number,
ac.order_date as order_date,
ac.note as note,
string_agg(cccd.description, ', ') as cause_description,
string_agg(cccd.cause, ', ' order by cccd.id) as cause
from auditors.persons p
left join auditors.governmental_register gr on p.id = gr.person_id
left join auditors.auditor_certificates ac on p.id = ac.person_id
left join auditors.certificate_change_cause_dictionary cccd on ac.cause_of_changes_id = cccd.id;