How to delete multiple rows in SQL where id = (x to y)

后端 未结 5 2014
甜味超标
甜味超标 2020-12-04 07:23

I am trying to run a SQL query to delete rows with id\'s 163 to 265 in a table

I tried this to delete less number of rows

    DELETE FROM `table` WHE         


        
5条回答
  •  盖世英雄少女心
    2020-12-04 08:21

    If you need to delete based on a list, you can use IN:

    DELETE FROM your_table
    WHERE id IN (value1, value2, ...);
    

    If you need to delete based on the result of a query, you can also use IN:

    DELETE FROM your_table
    WHERE id IN (select aColumn from ...);
    

    (Notice that the subquery must return only one column)

    If you need to delete based on a range of values, either you use BETWEEN or you use inequalities:

    DELETE FROM your_table
    WHERE id BETWEEN bottom_value AND top_value;
    

    or

    DELETE FROM your_table
    WHERE id >= a_value AND id <= another_value;
    

提交回复
热议问题