I am working on a way to delete multiple rows of a single SQL database, targeting two columns. ColumnA will always be the same value, and ColumnB will be different values.
I am trying to figure out the correct syntax for something like this:
DELETE FROM tableName WHERE (
ColumnA = 123 AND ColumnB = 1,
ColumnA = 123 AND ColumnB = 2,
ColumnA = 123 AND ColumnB = 3,
ColumnA = 123 AND ColumnB = 4,
ColumnA = 123 AND ColumnB = 8
);
What will be the correct SQL syntax for the above logic?
This will do it:
DELETE FROM tableName
WHERE ColumnA = 123 AND ColumnB IN (1, 2, 3, 4, 8)
Replace , with OR :
where (ColumnA = 123 and ColumnB = 1) or
(ColumnA = 123 and ColumnB = 2) or
. . .
(ColumnA = 123 and ColumnB = 8);
This can be also simplified as :
where ColumnA = 123 and
ColumnB in (1, 2, 3, 4, 8);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With