Skip to content
Advertisement

SQL – Get multiple values when limit 1

If I have a table like this:

And use this query: SELECT ident,COUNT(*) FROM sales WHERE status=? AND team=? AND DATE(date) = DATE(NOW() - INTERVAL 1 DAY) GROUP BY ident order by COUNT(*) DESC LIMIT 1

I get the value: cucu1, since that has the most rows.

But if my table is like this:

It should return both cucu1 and kkju7, since they are the highest with same count, but still it gives me only cucu1. What am I doing wrong?

Advertisement

Answer

You can use rank():

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