为此,请使用LIKE,如下所示-
select *from yourTableName where yourColumnName LIKE 'A%';
让我们首先创建一个表-
mysql> create table DemoTable ( StudentName varchar(100) );
现在您可以使用insert命令在表中插入一些记录-
mysql> insert into DemoTable values('John Smith'); mysql> insert into DemoTable values('Adam Smith'); mysql> insert into DemoTable values('Aaron Taylor'); mysql> insert into DemoTable values('Chris Brown');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+--------------+ | StudentName | +--------------+ | John Smith | | Adam Smith | | Aaron Taylor | | Chris Brown | +--------------+ 4 rows in set (0.00 sec)
以下是在MySQL中搜索以A开头的名称的查询-
mysql> select *from DemoTable where StudentName LIKE 'A%';
输出结果
+--------------+ | StudentName | +--------------+ | Adam Smith | | Aaron Taylor | +--------------+ 2 rows in set (0.00 sec)