Skip to content

Instantly share code, notes, and snippets.

@geekuillaume
Created August 3, 2018 12:34
Show Gist options
  • Save geekuillaume/6033b88e94561ffc975c5dd6cb63db5c to your computer and use it in GitHub Desktop.
Save geekuillaume/6033b88e94561ffc975c5dd6cb63db5c to your computer and use it in GitHub Desktop.
SELECT todo_lists.id AS id,
todo_lists.name,
jsonb_agg(to_jsonb(todo_items) - 'todo_list_id') AS items
FROM todo_lists
LEFT JOIN todo_items ON todo_items.todo_list_id = todo_lists.id
GROUP BY todo_lists.id;
@wiesys
Copy link

wiesys commented Dec 20, 2022

Excellent! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment