Skip to content

Instantly share code, notes, and snippets.

@slav123
Created July 17, 2020 08:56
Show Gist options
  • Save slav123/00b00046a02eca56996284b5c0f2d964 to your computer and use it in GitHub Desktop.
Save slav123/00b00046a02eca56996284b5c0f2d964 to your computer and use it in GitHub Desktop.
Single query to pull users with group names.
SELECT id, email, (SELECT GROUP_CONCAT(ag.name) FROM auth_groups_users gu LEFT JOIN auth_groups ag ON ag.id=gu.group_id WHERE gu.user_id=u.id ) FROM users u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment