MySQL查询找到匹配项并获取记录
要从记录中查找匹配项,请使用MySQLIN()。让我们首先创建一个表-
mysql> create table DemoTable
(
Id int,
FirstName varchar(20),
Gender ENUM('Male','Female')
);使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(1,'Chris','Male'); mysql> insert into DemoTable values(10,'Emma','Female'); mysql> insert into DemoTable values(9,'Emma','Male'); mysql> insert into DemoTable values(11,'Isabella','Female');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+------+-----------+--------+ | Id | FirstName | Gender | +------+-----------+--------+ | 1 | Chris | Male | | 10 | Emma | Female | | 9 | Emma | Male | | 11 | Isabella | Female | +------+-----------+--------+ 4 rows in set (0.00 sec)
以下是查找与ID1和11匹配并获取记录的查询-
mysql> select *from DemoTable where Id IN(1,11);
这将产生以下输出-
+------+-----------+--------+ | Id | FirstName | Gender | +------+-----------+--------+ | 1 | Chris | Male | | 11 | Isabella | Female | +------+-----------+--------+ 2 rows in set (0.00 sec)
热门推荐
10 舅妈生日红包祝福语简短
11 小姨生日祝福语简短独特
12 新年祝福语简短聪明可爱
13 奶奶八十寿辰祝福语简短
14 朋友花篮开业祝福语简短
15 周末祝福语简短的英语
16 工厂祝福语简短的句子
17 对女友的简短祝福语
18 提早庆祝生日祝福语简短