user34537
user34537

Reputation:

MySql find multiple rows with same value in a column

I record IP addresses in my DB and i want to look at accounts that have the same IP address as eachother. I'd like to show only results with more then one IP addresses. I preferentially would like it sorted by IP addressed used the most (IE if i have 30accounts with 127.0.0.1 as my ip i rather have that higher then 10ip address that belong to 192.168.1.123).

How do i write this query? I am using mysql

Upvotes: 4

Views: 5247

Answers (1)

Braden
Braden

Reputation: 617

SELECT ip, COUNT(*)
FROM Table    
GROUP BY ip    
HAVING COUNT(*) > 1    
ORDER BY COUNT(*);

Upvotes: 13

Related Questions