Search code examples
sqlsql-deleterecords

SQL Delete Records within a specific Range


This is probably a very simple question for somebody with experience, but I just wanted to know the safest way to delete a couple of hundred records in an SQL table that fall between a specific range.

For example I need to delete rows with an ID between 79 & 296:

My worry is if I say delete everything with an ID (>79 AND < 296) then it may literally wipe the whole table.


Solution

  • If you use Sql Server

    delete from Table where id between 79 and 296
    

    Note : the between statement is inclusive, so rows 79 and 296 will also be deleted

    After your edit : you now clarified that you want :

    ID (>79 AND < 296)

    So use this :

    delete from Table where id > 79 and id < 296