title: SQL select records with minimum number of related records
body: <p>monkey-hangouts relates many monkeys to many trees and vice-versa.  a monkey hangs out in multiple trees.  a tree hosts multiple monkeys.  the relation monkey-hangouts models the many to many monkeys to trees.</p>
  
  <p>a large proportion of monkeys hang out in only one tree.  i'd like a query of monkeys that hang out in multiple trees.  that is, monkeys with more than one related record in monkey-hangouts.  as a bonus, i'd like the query result to be the monkey X tree join of actual hangouts.</p>
  
  <p>here is a query that selects all of the monkeys with their hangouts. limit this to monkeys with more than one hangout.</p>
  
  <pre><code>select 
      m.*, t.* 
  from 
      monkeys m 
  inner join 
      monkey-hangouts h on m.id = h.monkey_id 
  inner join 
      trees t on t.id = h.tree_id 
  order by 
      m.id;
  </code></pre>