首页 > 数据库技术 > 详细

How to perform a SQL query for fields that are null (or not null)

时间:2015-06-18 22:00:38      阅读:260      评论:0      收藏:0      [点我收藏+]

 

Okay, maybe this is lame, but when I‘ve been away from writing SQL database queries for a while I can never remember how to search for database table fields that are either NULL, or NOT NULL. I always try to use the = operator or something else.

So, for you Al, here‘s how to perform a SQL query and find all records where a field in a database table is NULL:

SELECT * FROM foo WHERE bar IS NULL;

  

And here‘s how to perform a SQL query showing all records in a database table where a field is NOT NULL:

SELECT * FROM foo WHERE bar IS NOT NULL;

  

This works with every database I‘ve tried, including MySQL, Oracle, Postgres, and SQL Server.

How to perform a SQL query for fields that are null (or not null)

原文:http://www.cnblogs.com/hephec/p/4586890.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!