title: Determining count of unique combination of two fields in mysql
body: <p>I have the following table:</p>
  
  <pre><code>Company        webdomain
  -------        ---------
  IBM            ibm.com
  IBM            ibm.co.uk
  IBM            ibm.in
  CSC            csc.com
  Infosys        infy.com
  Intel          intel.com
  Intel          intel.co.in
  </code></pre>
  
  <p><strong>Question</strong>: how many companies have more than one webdomain?</p>
  
  <p>How do I represent this as a SQL query?</p>
  
  <p>I tried the following:</p>
  
  <pre><code>select count(distinct company, webdomain) 
  from table 
  where company = 'IBM';
  </code></pre>
  
  <p>This gave the number of web domains for IBM as 3, but however, when I want to create the same effect on finding out all companies with the following query:</p>
  
  <pre><code>select company, count(distinct company, webdomain) 
  from table;
  </code></pre>
  
  <p>I get a single column, which is an empty value on company and some unrelated count.</p>
  
  <p>I know that this will solve the problem:</p>
  
  <pre><code>select company, count(distinct company, webdomain) 
  from table 
  where company in (select distinct company from table);
  </code></pre>
  
  <p>But this last query takes way too long. Is there a better way to put it.</p>
  
  <p>EDIT: Company, webdomain combination may not be unique. Ex: Two records with IBM, ibm.com.</p>