frosty frosty - 1 year ago 54
MySQL Question

Selecting all messages from individual ips that has 20 or more messages

I'm trying to select all the messages from individual ips that has 20 or more messages, but I'm having trouble selecting it. Here's my query:

SELECT messages
FROM currentChat
HAVING count(id) >= 20
GROUP by ip

Answer Source

You could use a subquery to get your results

SELECT * 
FROM currentChat 
WHERE ip IN (SELECT ip FROM currentChat GROUP BY ip HAVING COUNT(*) >= 20)