title: MySQL: Invalid use of group function
body: <p>I am using MySQL. Here is my schema:</p>
  
  <p>Suppliers(<strong>sid: integer</strong>, sname: string, address string)</p>
  
  <p>Parts(<strong>pid: integer</strong>, pname: string, color: string)</p>
  
  <p>Catalog(<strong>sid: integer, pid: integer</strong>, cost: real)</p>
  
  <p>(primary keys are bolded)</p>
  
  <p>I am trying to write a query to select all parts that are made by at least two suppliers:</p>
  
  <pre><code>-- Find the pids of parts supplied by at least two different suppliers.
  SELECT c1.pid                      -- select the pid
  FROM Catalog AS c1                 -- from the Catalog table
  WHERE c1.pid IN (                  -- where that pid is in the set:
      SELECT c2.pid                  -- of pids
      FROM Catalog AS c2             -- from catalog
      WHERE c2.pid = c1.pid AND COUNT(c2.sid) &gt;= 2 -- where there are at least two corresponding sids
  );
  </code></pre>
  
  <p>First off, am I even going about this the right way?</p>
  
  <p>Secondly, I get this error: </p>
  
  <blockquote>
    <p>1111 - Invalid use of group function</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>