stevebot stevebot - 1 year ago 71
MySQL Question

Select where count of one field is greater than one

I want to do something like:

FROM db.table
WHERE COUNT(someField) > 1

how do I do this in MySql.

Answer Source

Use the HAVING, not WHERE clause, for aggregate result comparison.

Taking the query at face value:

  FROM db.table 
HAVING COUNT(someField) > 1

Ideally, there should be a GROUP BY defined for proper valuation in the HAVING clause, but MySQL does allow hidden columns from the GROUP BY...

Is this in preparation for a unique constraint on someField? Looks like it should be...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download