NOT LIKE
Description
The NOT LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the NOT LIKE operator:
- The percent sign (%) represents zero, one, or multiple characters.
- The underscore sign (_) represents one, single character.
Syntax
1. > SELECT column1, column2, ...
2. FROM table_name
3. WHERE columnN NOT LIKE pattern;
Examples
1. create table t1 (a char(10));
2. insert into t1 values('abcdef');
3. insert into t1 values('_bcdef');
4. insert into t1 values('a_cdef');
5. insert into t1 values('ab_def');
6. insert into t1 values('abc_ef');
7. insert into t1 values('abcd_f');
8. insert into t1 values('abcde_');
10. mysql> select * from t1 where a not like 'a%';
11. +--------+
12. | a |
13. +--------+
14. | _bcdef |
15. +--------+
16. mysql> select * from t1 where a not like "%d_\_";
17. +--------+
18. | a |
19. +--------+
20. | abc_ef |
21. +--------+
22. 1 row in set (0.01 sec)
