让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> Age int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(Name,Age) values('John',21); mysql> insert into DemoTable(Name,Age) values(Null,20); mysql> insert into DemoTable(Name,Age) values('David',23); mysql> insert into DemoTable(Name,Age) values('Carol',null);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 1 | John | 21 | | 2 | NULL | 20 | | 3 | David | 23 | | 4 | Carol | NULL | +----+-------+------+ 4 rows in set (0.00 sec)
以下是具有OR&AND条件的查询-
mysql> select *from DemoTable -> where Name='David' OR (Name is null AND Age=20);
输出结果
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 2 | NULL | 20 | | 3 | David | 23 | +----+-------+------+ 2 rows in set (0.00 sec)