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_');
  9. mysql> select * from t1 where a not like 'a%';
  10. +--------+
  11. | a |
  12. +--------+
  13. | _bcdef |
  14. +--------+
  15. mysql> select * from t1 where a not like "%d_\_";
  16. +--------+
  17. | a |
  18. +--------+
  19. | abc_ef |
  20. +--------+
  21. 1 row in set (0.01 sec)