使用带有AND&OR运算符的单个MySQL查询来获取特定记录
让我们首先创建一个表-
mysql> create table DemoTable2015 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentCountryName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable2015 values(1,'Chris','US'); mysql> insert into DemoTable2015 values(2,'Bob','UK'); mysql> insert into DemoTable2015 values(3,'David','AUS'); mysql> insert into DemoTable2015 values(4,'Robert','US');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable2015;
这将产生以下输出-
+-----------+-------------+--------------------+ | StudentId | StudentName | StudentCountryName | +-----------+-------------+--------------------+ | 1 | Chris | US | | 2 | Bob | UK | | 3 | David | AUS | | 4 | Robert | US | +-----------+-------------+--------------------+ 4 rows in set (0.00 sec)
这是通过单个查询获取特定记录的查询-
mysql> select *from DemoTable2015 -> where StudentName='David' OR StudentCountryName='UK' and StudentId=3;
这将产生以下输出-
+-----------+-------------+--------------------+ | StudentId | StudentName | StudentCountryName | +-----------+-------------+--------------------+ | 3 | David | AUS | +-----------+-------------+--------------------+ 1 row in set (0.00 sec)
热门推荐
10 高一祝福语简短 励志
11 立秋节气简短祝福语
12 简短公司周年祝福语大全
13 中考感言简短祝福语大全
14 体育老师简短祝福语
15 干杯生日祝福语简短独特
16 特别简短的祝福语老师
17 朋友坐车走了祝福语简短
18 给英雄的祝福语简短