views:

39

answers:

1

Hi,

How do we find the top 2 most populated cities i.e where no. of customers are higher than any other.I only have the SSN of the customers. They are unique and I am thinking of counting them for a particular city and check if that is higher than any other city.

+3  A: 

Assuming your schema looks like:

Customers
  -City
  -SSN

You should be able to simply use limit:

select City, count(SSN)
from Customers
group by City
order by count(SSN) desc
limit 2
Ian Henry
Do we need to where clause?
shilps
If you want to restrict the results in some way further, then yes. But this is sufficient for the question you asked.
Ian Henry