如何限制MySQL`LIKE`运算符以特定字符开头?
让我们首先创建一个表-
mysql> create table DemoTable ( FirstName varchar(40) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John'); mysql> insert into DemoTable values('Adam'); mysql> insert into DemoTable values('David'); mysql> insert into DemoTable values('Mike'); mysql> insert into DemoTable values('Sam');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+ |FirstName | +-----------+ | John | | Adam | | David | | Mike | | Sam | +-----------+ 5 rows in set (0.00 sec)
以下是限制`LIKE`运算符以特定字符开头的查询-
mysql> select *from DemoTable where FirstName LIKE 'D%' or FirstName LIKE 'S%';
这将产生以下输出-
+-----------+ | FirstName | +-----------+ | David | | Sam | +-----------+ 2 rows in set (0.00 sec)