I have the following table:
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
Question: how many companies have more than one webdomain?
How do I represent this as a SQL query?
I tried the following:
select count(distinct company, webdomain)
from table
where company = 'IBM';
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:
select company, count(distinct company, webdomain)
from table;
I get a single column, which is an empty value on company and some unrelated count.
I know that this will solve the problem:
select company, count(distinct company, webdomain)
from table
where company in (select distinct company from table);
But this last query takes way too long. Is there a better way to put it.
EDIT: Company, webdomain combination may not be unique. Ex: Two records with IBM, ibm.com.