Your query is interpreted as:
select distinct (ca.id) as id, acc.name as accName, . . .
This is a standard distinct
statement. If you want just one row per ca.id
with values from the first row (based on the order by
), then use distinct on
:
select distinct on (ca.id) ca.id, acc.name as accName, . . .