title: SQL Filter by count of records
body: <p>I have a table of the form: (Answer must work for PostGreSQL 9.2</p>
  
  <p>StateName, ContryName, Pop, etc.  // btw state may also be province, I use them interchangeabley</p>
  
  <p>I would like to remove any country that has too many states</p>
  
  <p>This does a filter, but since I am grouping by the country (states.admin) I get an error because states.name is not in the group clause.</p>
  
  <p>I want a filtered table, that just removes all rows for a country that more than 100 states.</p>
  
  <p>Am I making sense? I assume I need some sort of WHERE subquery.</p>
  
  <pre><code>SELECT 
    states.name,
    states.admin
  FROM
    vector.states
  GROUP BY 
    states.admin
  HAVING COUNT(*) &lt; 100
  ORDER BY
    states.admin ASC;
  </code></pre>