How to perform a SQL query for fields that is null (or NOT NULL)

Source: Internet
Author: User

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

So, for your Al, here's how to perform a SQL query and the 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 was 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 is null (or NOT NULL)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.