使用LIKE子句两次显示重复的名字和姓氏的表中的特定名称
让我们首先创建一个表-
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(30) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(StudentName) values('John Smith');
mysql> insert into DemoTable(StudentName) values('David Miller');
mysql> insert into DemoTable(StudentName) values('Carol Taylor');
mysql> insert into DemoTable(StudentName) values('John Doe');
mysql> insert into DemoTable(StudentName) values('Chris Brown');
mysql> insert into DemoTable(StudentName) values('Adam Doe');使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+---------------+ | StudentId | StudentName | +-----------+---------------+ | 1 | John Smith | | 2 | David Miller | | 3 | Carol Taylor | | 4 | John Doe | | 5 | Chris Brown | | 6 | Adam Doe | +-----------+---------------+ 6 rows in set (0.00 sec)
这是从表中选择名字为“John”和姓氏为“Doe”的记录的查询-
mysql> select *from DemoTable where StudentName LIKE '%John%' and StudentName LIKE '%Doe%';
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 4 | John Doe | +-----------+-------------+ 1 row in set (0.00 sec)
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿