What is NULL in SQL and how does three-valued logic work?
What is NULL in SQL and how does three-valued logic work?
NULL means unknown or missing, not zero and not an empty string. Because of that, SQL uses three-valued logic: a condition can be TRUE, FALSE or UNKNOWN.
SELECT 1 WHERE NULL = NULL; -- no row: UNKNOWN
SELECT 1 WHERE NULL <> 5; -- no row: UNKNOWN
SELECT 1 WHERE NULL IS NULL; -- row returned
WHERE, ON and HAVING keep only rows where the condition is TRUE; UNKNOWN rows are dropped.
| Expression | Result |
|---|---|
TRUE AND UNKNOWN |
UNKNOWN |
FALSE AND UNKNOWN |
FALSE |
TRUE OR UNKNOWN |
TRUE |
NOT UNKNOWN |
UNKNOWN |
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.