title: Mysql Join query using a group by
body: <p>I'm trying to write a query that will return ...</p>
  
  <ol>
  <li><p>Each distinct user id in the accesslog table.</p></li>
  <li><p>A count of how many distinct ip addresses each userid has accessed the site with, also from the accesslog table.</p></li>
  <li><p>That userid's name, email address, and company name, from the users table.</p></li>
  </ol>
  
  <p>I've got 1 and 2, but I'm not sure how to get 3. I suck at joins, I admit. :(</p>
  
  <p>Here's the query I have now:</p>
  
  <pre><code>SELECT DISTINCT userid, COUNT(ipaddress) AS c FROM accesslog WHERE url LIKE 'www.example.com%' and userid != '' GROUP BY userid ORDER BY c desc
  </code></pre>
  
  <p>How would I <code>JOIN</code> in the other pieces of data that I want?</p>