NULL and Empty Values Print

  • databasesphpmyadmin, databases, phpmyadmin, guide, howto, solution, zillionkinghost, hosting
  • 0

A distinction that causes bugs.

THE DIFFERENCE

NULL means no value exists. An empty string means a value exists and it is empty.

They are not the same, and comparing them behaves differently.

WHY IT MATTERS

A query using WHERE column = '' does not match NULL rows.

A query using WHERE column IS NULL does not match empty strings.

Checking for both requires saying so explicitly.

THE CORRECT COMPARISON

IS NULL and IS NOT NULL. Never = NULL, which matches nothing, including rows that are NULL.

This surprises people and produces queries that silently return nothing.

IN COUNTS

COUNT(column) ignores NULL values. COUNT(*) counts every row.

A count that seems too low is frequently this.

IN SORTING

NULL values sort together, at one end depending on direction.

WHEN YOU SEE IT

Browsing in phpMyAdmin shows NULL in italics, distinguishing it from an empty cell.

PRACTICAL ADVICE

When a query returns fewer rows than expected, check whether NULL values are being excluded by your comparison.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot