Search PHPMYADMIN Database for similar entrys

前端 未结 3 1966
长情又很酷
长情又很酷 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    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.

提交回复
热议问题