mysql> SELECT name FROM tb_students_info -> WHERE name LIKE 'T%'; +--------+ | name | +--------+ | Thomas | | Tom | +--------+ 2 rows in set (0.12 sec) 可以看到,查询结果中只返回了以字母“T”开头的学生姓名。
mysql> SELECT NAME FROM tb_students_info -> WHERE NAME NOT LIKE 'T%'; +-------+ | NAME | +-------+ | Dany | | Green | | Henry | | Jane | | Jim | | John | | Lily | | Susan | +-------+ 8 rows in set (0.00 sec) 可以看到,查询结果中返回了不以字母“T”开头的学生姓名。
mysql> SELECT name FROM tb_students_info -> WHERE name LIKE '%e%'; +-------+ | name | +-------+ | Green | | Henry | | Jane | +-------+ 3 rows in set (0.00 sec) 可以看到,查询结果中返回了所有包含字母“e”的学生姓名。
mysql> SELECT name FROM tb_students_info -> WHERE name LIKE '____y'; +-------+ | name | +-------+ | Henry | +-------+ 1 row in set (0.00 sec) LIKE 区分大小写
mysql> SELECT name FROM tb_students_info WHERE name LIKE 't%'; +--------+ | name | +--------+ | Thomas | | Tom | +--------+ 2 rows in set (0.00 sec) mysql> SELECT name FROM tb_students_info WHERE name LIKE BINARY 't%'; Empty set (0.01 sec) 由结果可以看到,区分大小写后,“Tom”和“Thomas”等记录就不会被匹配到了。