MySQL按某些匹配字母查询表

来源:岁月联盟 编辑:猪头三 时间:2010-11-20

MySQL查询是MySQL的核心功能,有时候我们需要查找带有某些匹配字母的表。下文对该MySQL查询方式作了详细的介绍,供您参考。

在MySQL中我们可以使用LIKE或者NOT LIKE操作符进行比较。在MySQL中模式默认是不区分大小写的。

查询示例,student表
+--------+---------+-------+-----------------+---------+
| studid | name    | marks | address         | phone   |
+--------+---------+-------+-----------------+---------+

mysql> select * from student where name like 'm%';
列出在表student中所有以字母M开头的学生名字。 

mysql> select * from student where name like '%e';
列出所有以字母e结尾的学生名字。

mysql> select * from student where name like '%a%';
列出在任何地方包含任何特定字母的学生名字。以下的查询示例将列出包含"a"字母的学生名字。

mysql> select * from student where name like '_____';
假如我们要查找的名字包括5个字母,我们就可以使用特殊的字母"_"(下划线)。将列好在表student中包括5个字母学生的名字。