I did this quiz on http://www.sql-ex.ru/, question 35 to be exact.
The question is as follows: In Product table, determine the models which consist only of digits or only of latin letters (A-Z, case insensitive). Result set: model, type of model.
And I gave the correct answer which is:
SELECT model,
type
FROM Product
WHERE Model NOT LIKE '%[^A-Z]%'
OR Model NOT LIKE '%[^0-9]%'
Now my question is why do I need double negations to make it work. If I rewrite the code to:
SELECT model,
type
FROM Product
WHERE Model LIKE '%[A-Z]%'
OR Model LIKE '%[0-9]%'
I get the wrong answer: Your query returned the correct dataset on the first (available) database, but it returned incorrect dataset on the second checking database. * Wrong number of records (more by 37)
How come that the first example of code gives the correct answer while the second example doesn´t?
I have tried to find answer but no luck. Grateful for an explanation.