title: Redshift query to identify users belonging to specific groups
body: <p>I have a redshift table (<code>user_group</code>) that looks like</p>
  
  <pre><code>user_id | group_id
  --------+---------
  1       | 1
  1       | 2
  2       | 1
  2       | 3
  3       | 2
  3       | 3
  4       | 4
  </code></pre>
  
  <p>What's the best way to write a query that returns all users (<code>user_id</code>) who belong to some arbitrary subset of groups (<code>group_id</code>)?</p>
  
  <p>Right now, my hacked query is as follows, where I just add/remove <code>WHERE</code> filters as needed:</p>
  
  <pre><code>SELECT DISTINCT user_id
  FROM
      user_group
  WHERE
      user_id IN (SELECT DISTINCT user_id FROM user_group WHERE group_id = 1)
      AND user_id IN (SELECT DISTINCT user_id FROM user_group WHERE group_id = 5)
      ...
  </code></pre>
  
  <p>And, it feels like there should be a better way?</p>