Skip to content

Instantly share code, notes, and snippets.

@jkatz
Created November 2, 2011 18:58
Show Gist options
  • Save jkatz/1334532 to your computer and use it in GitHub Desktop.
Save jkatz/1334532 to your computer and use it in GitHub Desktop.
SELECT a.*, my_list.list
FROM (
SELECT a.id, array_agg(b.id) AS list
FROM a
JOIN b ON a.id = b.a_id
GROUP BY a.id
) my_list
JOIN a ON a.id = my_list.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment