php - Find identical IP from database and combine it to one result

576

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)

473

Answer

Solution:

How about

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

People are also looking for solutions to the problem: php - Where working for only one column

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.