Daniel Yeffet Daniel Yeffet - 6 months ago 10
SQL Question

Find identical IP from database and combine it to one result

I have a table named "ips" that contains all of my users IPs.
I want to find duplicated accounts and report it for me.
I want to see all users that have the same IP, for example:
"a" has the same ip as "b", and "c" has the same ip as "d".
So I want to get a query that gets me-

User 1: "a", User 2: "b", ip: 127.0.0.1
User 1: "c", User 2: "d", ip: 256.0.0.2


What's the best query to do so? (PHP/Mysql)

Answer

How about

select ip, group_concat(user_name) as users
from ips
group by ip
having count(*) > 1
Comments