October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Use IS NULL: Why SQL = NULL Finds No Rows

Use IS NULL to find SQL NULL values. Ordinary comparisons such as = NULL evaluate to UNKNOWN, so they do not match rows in a WHERE clause.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To find rows where a column is NULL, write WHERE column_name IS NULL; to exclude them, write WHERE column_name IS NOT NULL. A condition such as WHERE column_name = NULL does not match those rows because ordinary SQL comparisons with NULL evaluate to UNKNOWN, not TRUE.

Why does = NULL return no rows?

NULL represents an unknown or missing value, not an ordinary value that equality can compare. In PostgreSQL, an ordinary comparison returns NULL—meaning “unknown”—when either input is NULL. MySQL likewise explains that a comparison with NULL is not true. A WHERE clause selects rows only when its condition is true, so WHERE phone = NULL does not select rows with a NULL phone value. See the PostgreSQL comparison documentation and MySQL’s NULL guidance.

As an Amazon Associate I earn from qualifying purchases.

What should you write instead?

Find NULL values

SELECT *
FROM contacts
WHERE phone IS NULL;

IS NULL tests whether the value is NULL and returns a definite true-or-false result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Exclude NULL values

SELECT *
FROM contacts
WHERE phone IS NOT NULL;

IS NOT NULL matches rows where the expression has a value.

Test for an empty string separately

SELECT *
FROM contacts
WHERE phone = '';

An empty string is not the same as NULL. MySQL explicitly distinguishes the two: use IS NULL for a NULL value and = '' for an empty string. This distinction matters when interpreting or cleaning data; a column can contain either, both, or neither. See MySQL’s examples.

Why can NULL change a larger condition?

SQL uses three-valued logic: TRUE, FALSE, and UNKNOWN, represented by NULL. Consequently, a condition containing NULL does not always behave like ordinary two-valued Boolean logic. For example, TRUE OR NULL is TRUE, while NOT NULL remains NULL; FALSE AND NULL is FALSE. A filter still selects only a condition that evaluates to TRUE. PostgreSQL documents these rules in its logical-operators reference.

When debugging a compound WHERE clause, work out the result of each comparison first. Replacing = NULL with IS NULL is appropriate when the intent is to test whether one expression is NULL; it is not a general rewrite for every expression involving NULL.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do you compare two values when either might be NULL?

If the intent is to compare two expressions while treating two NULLs as equal, use a null-safe equality predicate supported by your database. PostgreSQL provides IS NOT DISTINCT FROM:

WHERE a IS NOT DISTINCT FROM b

This treats two NULL inputs as equal and treats one NULL and one non-NULL input as unequal. Its inverse, IS DISTINCT FROM, treats those two cases as distinct. These predicates answer a different question from a IS NULL: the latter tests one expression for nullness, while the former compares two expressions. PostgreSQL documents both in its comparison reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Does the syntax vary by database?

IS NULL and IS NOT NULL are the direct nullness tests shown in the cited PostgreSQL, MySQL, and SQLite documentation. For null-safe equality between two expressions, check the target database’s documentation rather than assuming shorthand is portable.

  • PostgreSQL: supports IS DISTINCT FROM and IS NOT DISTINCT FROM. It also documents a compatibility setting, transform_null_equals, that can rewrite x = NULL to x IS NULL when enabled. PostgreSQL recommends changing application queries to use the standard null test instead of relying on that setting. PostgreSQL comparison documentation.
  • SQLite: provides null-aware IS and IS NOT comparisons. Its documentation identifies the compact forms as SQLite extensions and points to IS [NOT] DISTINCT FROM forms used by other database engines. SQLite expression documentation.
  • MySQL: documents IS NULL and IS NOT NULL; it also notes that an IS NULL search can use indexes and ranges where applicable. MySQL NULL guidance and MySQL IS NULL optimization.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.