使用带有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 夏日升学宴祝福语简短