SQL - WHERE AGGREGATE>1

aggregate, informix, sql

Solution

You want the `having` clause, like so:

select 
    firstname,
    count(*) 
from Customers 
group by firstname
having count(*) > 1
order by 1

Problem

Imagine I have a db table of Customers containing {id,username,firstname,lastname} If I want to find how many instances there are of different firstnames I can do: ``` select firstname,count(*) from Customers group by 2 order by 1; username | count(*) =================== bob | 1 jeff | 2 adam | 5 ``` How do I write the same query to only return firstnames that occur more than once? i.e. in the above example only return the rows for jeff and adam.

Original source

Related problems