Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete several values in SQL?

Tags:

sql

oracle

I know how to delete a set of rows with a statements like these:

DELETE FROM my_table WHERE id=23 AND year=2012 AND value=16
DELETE FROM my_table WHERE id=17 AND year=2012 AND value=16
DELETE FROM my_table WHERE id=64 AND year=2012 AND value=16

But I would like to combine the above three statements into a single DELETE where id is either 23, 17, or 64.

What is the syntax for doing this in Oracle SQL?

like image 301
WilliamKF Avatar asked Nov 30 '22 22:11

WilliamKF


1 Answers

You can use the SQL IN keyword. For example:

DELETE FROM my_table WHERE id IN (23, 17, 64) AND year=2012 AND value=16

Note: Oracle has a limit of 1,000 items in a list.

like image 178
Mike Christensen Avatar answered Dec 04 '22 08:12

Mike Christensen