32

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?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Ariod
  • 5,757
  • 22
  • 73
  • 103

4 Answers4

76

You have missed out the field name id in the second NOT LIKE. Try:

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

The AND in the where clause joins 2 full condition expressions such as id NOT LIKE '1%' and can't be used to list multiple values that the id is 'not like'.

mikej
  • 65,295
  • 17
  • 152
  • 131
15

You need to specify the column in both expressions.

SELECT * FROM transactions WHERE id NOT LIKE '1%' AND id NOT LIKE '2%'
tvanfosson
  • 524,688
  • 99
  • 697
  • 795
14

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%'
martin clayton
  • 76,436
  • 32
  • 213
  • 198
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%"

Bumblebee
  • 21
  • 1