I\'m using postgres 9.4, I have the following query:
SELECT pid, code, name FROM activity, ( SELECT code FROM project ) projects WHERE activity.pcode = project
SELECT pid from activity a, ( select json_agg(project) from project where code = a.code ) as p
Something like that ...