Returning all data from a table
Select some columns
Filtering rows
Logic
Text patterns
To be or NULL to be
21. Comparisons with NULL
A bit of mathematics
Let's practice

Instruction

Good job! Remember, NULL is a special value. It means that some piece of information is missing or unknown.

If you try evaluate a condition on a particular column, say Age < 70, the rows where age is NULL will always be excluded from the result set. Let's check this out in a practice exercise.

Note: in no way does NULL equal zero when used in numerical expressions. Even more interesting is the fact that the expression NULL = NULL is never true in T-SQL!

Exercise

Select all columns for cars whose price is greater than or equal to zero.

Note that the Opel with an unknown price is not in the result set. This confirms what we noted earlier – that NULL is not treated as numerical zero.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Car
WHERE Price >= 0;