Delete many rows from a table using id in Mysql

前端 未结 9 1900
遇见更好的自我
遇见更好的自我 2021-01-30 15:38

I am a Linux admin with only basic knowledge in Mysql Queries

I want to delete many table entries which are ip address from my table using id,

9条回答
  •  死守一世寂寞
    2021-01-30 16:30

    The best way is to use IN statement :

    DELETE from tablename WHERE id IN (1,2,3,...,254);
    

    You can also use BETWEEN if you have consecutive IDs :

    DELETE from tablename WHERE id BETWEEN 1 AND 254;
    

    You can of course limit for some IDs using other WHERE clause :

    DELETE from tablename WHERE id BETWEEN 1 AND 254 AND id<>10;
    

提交回复
热议问题