Home > Mobile >  Delete ranges of id's
Delete ranges of id's

Time:02-11

I have this huge SQL query which I would like to reduce:

DELETE
FROM users
WHERE id in (754, 755, 756, 757, 758, 759, 795, 796, 797, 798, 799, 765,
766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794);

I tried:

DELETE
FROM users
WHERE id => 754 AND id <= 759
AND id => 795 AND id <= 799
AND id => 765 AND id <= 794;

But I get error:

ERROR: syntax error at or near "=>"
Position: 42

Do you know how I can fix this issue?

CodePudding user response:

You could do it this way:

DELETE
FROM users
WHERE 
   id between 754 and 759
OR id between 765 and 799

CodePudding user response:

use >= operator

example

delete from users where id >= 754
  • Related