In a PostgreSQL table, I wan't to delete some values with conditions. This conditions are based on the begining of a field with a substr. In my example, I want to delete the values not starting with '01' or '02' or '03'. When I first run a SELECT on my values with conditions, it's ok.
Sample data
id | serial_number
---------------------
1 | 01A
2 | 01B
3 | 02A
4 | 02B
5 | 03A
6 | 03B
7 | 03C
8 | 04A
9 | 05A
10 | 06A
Example of a selection
SELECT * FROM my_table
WHERE substr(serial_number, 1, 2) LIKE '01' OR substr(serial_number, 1, 2) LIKE '02' OR substr(serial_number, 1, 2) LIKE '03'
But when I apply the same conditions in a DELETE and add a negation, it removes eveything. I need to change operators from OR to AND.
Delete with same condition (not expected result)
DELETE FROM my_table
WHERE substr(serial_number, 1, 2) NOT LIKE '01' OR substr(serial_number, 1, 2) NOT LIKE '02' AND substr(serial_number, 1, 2) NOT LIKE '03'
Delete with different operators (expected result)
DELETE FROM my_table
WHERE substr(serial_number, 1, 2) NOT LIKE '01' AND substr(serial_number, 1, 2) NOT LIKE '02' AND substr(serial_number, 1, 2) NOT LIKE '03'
How multiple conditions could be true with a AND ? It's not cumulative. I don't understand why I need to change operators.