title: MySQL - Select row if appear more than x times in other table
body: <p>Lets say I have two tables, Members and Orders with a 1:N relation:</p>
  
  <pre><code>Members         | Orders
  UserID  Name    | OrderID   UserID  Name
  111     Peter   | 777       111     Peter
  222     Bart    | 888       333     Joe
  333     Joe     | 999       111     Peter
  444     Andrew  | 101       444     Andrew
                  | 102       111     Peter
                  | 103       333     Joe
  </code></pre>
  
  <p>I am trying to get the Members ID from the Members table, in case that Member has more than 1 order in the Orders table.</p>
  
  <p>So the result should be...</p>
  
  <pre><code>Members
  UserID  Name
  111     Peter
  333     Joe
  </code></pre>
  
  <p>...because Peter and Joe both have at least 2 orders in the Orders table.</p>
  
  <hr>
  
  <p>I have tried to get a result with:</p>
  
  <pre><code>SELECT
      s.UserID,
  FROM Members s
      INNER JOIN Orders o
          ON s.UserID = o.UserID
  WHERE
      s.UserID IN
      (
          SELECT UserID
          FROM Orders
          GROUP BY UserID
          HAVING COUNT(*) &gt; 5
      )
  </code></pre>
  
  <p>But that gives me Peter back 3 times, and Joe 2 times; so I get duplicates instead of each UserID once. How can I get the result without duplicates?</p>