[sql] 'NOT LIKE' in an SQL query

Why does this simple query return 'ORA-00936: missing expression' (the database is Oracle as you can tell):

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND NOT LIKE '2%'

I feel silly, but what am I doing wrong?

This question is related to sql oracle ora-00936

The answer is


You've missed the id out before the NOT; it needs to be specified.

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND id NOT LIKE '2%'

You need to specify the column in both expressions.

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND id NOT LIKE '2%'

After "AND" and after "OR" the QUERY has forgotten what it is all about.

I would also not know that it is about in any SQL / programming language.

if(SOMETHING equals "X" or SOMETHING equals "Y")

COLUMN NOT LIKE "A%" AND COLUMN NOT LIKE "B%"