Search PHPMYADMIN Database for similar entrys

前端 未结 3 1959
长情又很酷
长情又很酷 2021-01-17 00:23

So i have database with a table called users.. and in that table there is a column named IP and i want to find users with the same IP and ban them.. So how can a search the

相关标签:
3条回答
  • 2021-01-17 00:55

    You can start by:

    SELECT count(id) FROM tablename
    GROUP BY IP
    

    Then you just join those results back onto the table to get information about the duplicates

    So modify the first statement with: SELECT count(id) as number, IP FROM tablename

    Then

       SELECT a.id, a.name FROM tablename a
       JOIN (
            SELECT count(id) as number, IP FROM tablename
        ) b ON a.IP = b.IP
        WHERE number > 1
    

    This should give you all the duplicate IP addresses in the Database. You may have to figure out a way to decide on which account to keep and which to remove, but this should give you a start.

    0 讨论(0)
  • 2021-01-17 01:00

    You should leverage the group by query. An old blog I wrote is Understanding group bys

    But basically this should work:

    select distinct ip, count(id) from users group by IP having count(id) > 1
    

    This will return all ip addresses with a count of > 1

    0 讨论(0)
  • 2021-01-17 01:15

    Run a SQL statement and substitute for the IP address you want to search for:

    SELECT * FROM users WHERE IP = '172.0.0.1'
    
    0 讨论(0)
提交回复
热议问题