在单个MySQL查询中实现多个LIKE运算符
要实现多个LIKE子句,语法如下-
select * from yourTableName
where yourColumnName1 LIKE ('%yourValue1%' or yourColumnName2 LIKE '%yourValue2%') or (yourColumnName3 LIKE '%yourValue3');让我们首先创建一个表-
mysql> create table DemoTable1534 -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int, -> ClientCountryName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('Chris Brown',29,'AUS');
mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('David Miller',49,'UK');
mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('John Doe',43,'US');
mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('Adam Smith',38,'US');
mysql> insert into DemoTable1534(ClientName,ClientAge,ClientCountryName) values('Carol Taylor',36,'UK');使用select语句显示表中的所有记录-
mysql> select * from DemoTable1534;
这将产生以下输出-
+----------+--------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+--------------+-----------+-------------------+ | 1 | Chris Brown | 29 | AUS | | 2 | David Miller | 49 | UK | | 3 | John Doe | 43 | US | | 4 | Adam Smith | 38 | US | | 5 | Carol Taylor | 36 | UK | +----------+--------------+-----------+-------------------+ 5 rows in set (0.00 sec)
以下是在单个查询中查询多个LIKE运算符的用法-
mysql> select * from DemoTable1534
-> where ClientName LIKE ('%Doe%' or ClientAge LIKE '%38%') or (ClientCountryName LIKE '%S');这将产生以下输出-
+----------+-------------+-----------+-------------------+ | ClientId | ClientName | ClientAge | ClientCountryName | +----------+-------------+-----------+-------------------+ | 1 | Chris Brown | 29 | AUS | | 3 | John Doe | 43 | US | | 4 | Adam Smith | 38 | US | +----------+-------------+-----------+-------------------+ 3 rows in set, 5 warnings (0.00 sec)
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下