How to remove duplicates, which are generated with array_agg postgres function
You can use the distinct
keyword inside array_agg
:
SELECT ARRAY_TO_STRING(ARRAY_AGG(DISTINCT CONCAT(u.firstname, ' ', u.lastname)), ', ')FROM log_has_item logitem INNER JOIN log log ON log.id = logitem.log_id INNER JOIN worker u ON log.worker_id = u.idWHERE logitem.company_id = 1