Skip to content
Advertisement

GROUP BY and WHERE clause in one query

I am trying to get all rows where the states are greater than 1.

My table:

My query:

Result is:

But I need print only values where is count(state) greater than 1

I am trying this, but it doesn’t work:

My example: http://www.sqlfiddle.com/#!9/b2716b/2

Advertisement

Answer

HAVING can filter unnecessary rows for you when there is GROUP BY applied. Try this following query for your purpose. WHERE clause is used for filtering rows and it applies on each and every row, while HAVING clause is used to filter groups in SQL

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement