Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created September 1, 2010 22:15
Show Gist options
  • Save zeroeth/561471 to your computer and use it in GitHub Desktop.
Save zeroeth/561471 to your computer and use it in GitHub Desktop.
-- supplied with two group ids, return all users with ONLY those two groups.
SELECT users.*, count(*) as grp_count
FROM users
JOIN users_groups
ON users.id = users_groups.user_id
WHERE users_groups.group_id in (730, 733)
GROUP BY users.id
HAVING count(*) = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment