tags:

views:

34

answers:

1

hi,

i want to make a selection that excludes the entries that start with 07, 0256 and 0356. this is what i tired:

SELECT * FROM rapoarte WHERE nrtel NOT LIKE '07%' OR nrtel NOT LIKE '0256%' OR nrtel NOT LIKE '0356%'

but it keeps selecting all the entries.

+6  A: 

The condition nrtel NOT LIKE '0256%' OR nrtel NOT LIKE '0356%' is always true (unless nrtel is NULL). You need to use AND:

SELECT * FROM rapoarte
WHERE nrtel NOT LIKE '07%' 
AND nrtel NOT LIKE '0256%'
AND nrtel NOT LIKE '0356%'

Or you could rewrite it as follows if you find it easier to read:

SELECT * FROM rapoarte
WHERE NOT (
   nrtel LIKE '07%' OR 
   nrtel LIKE '0256%' OR 
   nrtel LIKE '0356%'
)

The expression (NOT a) OR (NOT B) is not the same as NOT (a OR b). See De Morgan's Laws.

Mark Byers
(NOT A) OR (NOT B) == NOT ( A AND B )
racar
the queries work in mysql, but not in PHP. i don't get any results.
sebastian