mysql语句,mysql中is null语句的用法分享

mysql数据库中is null语句的用法
注意在mysql中,0或 null意味着假而其它值意味着真。布尔运算的默认真值是1。
对null的特殊处理即是在前面的章节中,为了决定哪个动物不再是活着的,使用death is not null而不使用death != null的原因。
在group by中,两个null值视为相同。
执行order by时,如果运行 order by ... asc,则null值出现在最前面,若运行order by ... desc,则null值出现在最后面。
null操作的常见错误是不能在定义为not null的列内插入0或空字符串,但事实并非如此。在null表示"没有数值"的地方有数值
。使用is [not] null则可以很容易地进行测试
is null or = null
mysql>
mysql> create table topic(
-> topicid smallint not null auto_increment primary key,
-> name varchar(50) not null,
-> instock smallint unsigned not null,
-> _disibledevent=> -> order by name;
empty set (0.00 sec)
mysql>
mysql>
mysql> drop table topic;
query ok, 0 rows affected (0.00 sec)
<=>null: null不等空
null意味着“没有值”或www.3ppt.com“未知值”,且它被看作与众不同的值。为了测试null,你不能使用算术比较 操作符例如=、<或!=
mysql>
mysql> select name, department, category
-> from topic
-> where category<=>null
-> order by name;
empty set (0.00 sec)
mysql>
mysql> drop table topic;
query ok, 0 rows affected (0.02 sec)
is not null
mysql> select name, department, category
-> from topic
-> where category is not null
-> order by name;
+----------------+------------+----------+
| name | department | category |
+----------------+------------+----------+
| asp.net | popular | country |
| c | classical | dance |
| c sharp | popular | jazz |
| c++ | classical | general |
| java | popular | rock |
| javascript | classical | opera |
| oracle | classical | general |
| perl | classical | vocal |
| php | popular | jazz |
| pl/sql | classical | opera |
| python | popular | blues |
| sql server | classical | general |
| uml | classical | general |
| vb.net | popular | new age |
| vc.net | popular | new age |
| www.java2s.com | classical | dance |
+----------------+------------+----------+
16 rows in set (0.00 sec)
mysql>
mysql> drop table topic;
query ok, 0 rows affected (0.00 sec)
Tags:  mysql用法 mysql语句

延伸阅读

最新评论

发表评论