title: MySQL count multiple foreign keys
body: <p>So I have a query where I select from the 'sites' table, and count the number of 'pages' using a foreign key</p>
  
  <pre><code>SELECT s_id, s_name, s_main_url, COUNT(p_id) AS numpages
  FROM sites
  INNER JOIN pages ON sites.s_id = pages.site_id
  GROUP BY pages.site_id
  ORDER BY s_id ASC
  </code></pre>
  
  <p>I want to add another foreign key to count, possibly more than one, so I tried the below</p>
  
  <pre><code>SELECT s_id, s_name, s_main_url, COUNT(p_id) AS numpages, COUNT(l_id) AS numlinks
  FROM sites
  INNER JOIN pages ON sites.s_id = pages.site_id
  INNER JOIN links ON sites.s_id = links.site_id
  GROUP BY pages.site_id, links.site_id
  ORDER BY s_id ASC
  </code></pre>
  
  <p>The count for both numpages and numlinks are the same, and they seem to have multiplied all the tables results and is giving me some huge number that is incorrect</p>
  
  <p>Any ideas?</p>