SQL Delete Records within a specific Range

user964769 picture user964769 · Nov 22, 2011 · Viewed 151.5k times · Source

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.

Answer

Royi Namir picture Royi Namir · Nov 22, 2011

if you use Sql Server

delete from Table where id between 79 and 296

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