tags:

views:

235

answers:

2

i have a table with coloumn id , name and city

I want to fetch those rows where city is same and the number of rows are greater than 3. Is it possible in single sql query?

A: 

Yes, it is pretty much the level of query I use to filter out the "I know SQL" people that dont have a clue about the language.

Lets see whether I get that together.

SELECT city, count() from TABLE GROUP BY city HAVING COUNT() >3

Simple beginner SQL

Not sure mysql supports it ;) But it is apart of the standard for ages.

http://www.w3schools.com/SQL/sql_having.asp

has more explanations.

TomTom
A: 

Yes it is:

SELECT city, COUNT(id) AS [rowcount]
FROM YourTable
GROUP BY city
HAVING COUNT(id) > 3
Prutswonder
i tried but coudn't achieve it Prutswonder.
saurav
Query was incorrect, "rowcount" is a reserved keyword, so I placed it in block quotes. If that doesn't work, could you post the query you're attempting and the SQL error you receive when you run it?
Prutswonder