S
S
savandr2021-11-16 00:16:18
SQL
savandr, 2021-11-16 00:16:18

SQL: Like and NOT LIKE?

Standard task: in the Product table, find models that consist only of numbers or only of Latin letters (AZ, case insensitive).
Output: model number, model type.

Correct answer:

SELECT model, type FROM Product
WHERE model NOT like '%[^0-9]%' OR upper(model) NOT like '%[^A-Z]%'

I can't understand why NOT LIKE and not just LIke in the query? Isn't NOT like '%[^....] just LIKE as a double negative?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikolay Savelyev, 2021-11-16
@AgentSmith

LIKE doesn't work with regular expressions. This is your mistake

S
Shockoway, 2015-03-06
@Shockoway

Just show the client examples of great sites from his competitors.

D
Dmitry Evgrafovich, 2015-03-19
@Tantacula

Can you solve some customer problems by creating a personal website or just want to make money on them?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question