在 MySQL 查询中两次使用 LIKE 子句
mysqlmysqli database更新于 2024/12/18 9:16:17
首先我们创建一个表 −
mysql> create table DemoTable2009 ( Name varchar(20) ); Query OK, 0 rows affected (0.51 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable2009 values('John Doe');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable2009 values('Adam Smith');
Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable2009 values('John Smith');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable2009 values('David Miller');
Query OK, 1 row affected (0.18 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable2009;
这将产生以下输出 −
+--------------+ | Name | +--------------+ | John Doe | | Adam Smith | | John Smith | | David Miller | +--------------+ 4 rows in set (0.00 sec)
这是在 MySQL 查询中两次使用 LIKE 子句的查询 −
mysql> select * from DemoTable2009 where Name like '%Smith%' or Name like '%David%';
这将产生以下输出 −
+--------------+ | Name | +--------------+ | Adam Smith | | John Smith | | David Miller | +--------------+ 3 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

