如何在 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;
输出
+--------------+ | 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)
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP