若要选择非空记录,请使用IS NOT NULL属性。让我们首先创建一个表-
mysql> create table DemoTable1792 ( Name varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1792 values('John Smith'); mysql> insert into DemoTable1792 values(NULL); mysql> insert into DemoTable1792 values('David Miller'); mysql> insert into DemoTable1792 values(NULL);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1792;
这将产生以下输出-
+--------------+ | Name | +--------------+ | John Smith | | NULL | | David Miller | | NULL | +--------------+ 4 rows in set (0.00 sec)
以下是查询以选择没有空记录的数据-
mysql> select * from DemoTable1792 where Name IS NOT NULL;
这将产生以下输出-
+--------------+ | Name | +--------------+ | John Smith | | David Miller | +--------------+ 2 rows in set (0.00 sec)