MySQL 如何搜索以A开头的名字
使用LIKE,如下所示−
select *from yourTableName where yourColumnName LIKE 'A%';
让我们首先创建一个表−
mysql> create table DemoTable
(
StudentName varchar(100)
);
Query OK, 0 rows affected (0.66 sec)
现在,您可以使用insert命令在表中插入一些记录−
mysql> insert into DemoTable values('John Smith');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values('Adam Smith');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('Aaron Taylor');
Query OK, 1 row affected (0.43 sec)
mysql> insert into DemoTable values('Chris Brown');
Query OK, 1 row affected (0.27 sec)
使用select语句显示表中的所有记录−
mysql> select *from DemoTable;
阅读更多:MySQL 教程
输出
+--------------+
| 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)