Lecture 3 - 3-valued SQL and NULL Flashcards
What is the three-valued logic of SQL?
TRUE (1), FALSE (0) and UNKNOWN(0.5)
What are the principles of NULL values?
- That each null value is different from another
- any value compared to NULL is null
What do we need to adopt to compare to NULL?
IS / IS NOT NULL
min / or with UNKNOWN?
Will evaluate to UNKNOWN unless there is a false and unknown combination
max / and with UNKNOWN?
TRUE WITH UNKNOWN IS TRUE OTHERWISE UNKNOWN
difference / not with NULL?
TRUE = FALSE
FALSE = TRUE
UNKNOWN = UNKNOWN
Why won’t this work:
COMPARISON INVOLVING NULL
SELECT Fname, Lname
FROM EMPLOYEE
WHERE Super_ssn = NULL
As Super_ssn = NULL will always evaluate to unknown, which will false when we take min
Why won’t the following work?
SELECT *
FROM EMPLOYEE
WHERE DNO NOT IN (1, 2, NULL)
This won’t work as we are not checking for NULL with the IS statement, because of this the boolean will result in UKNOWN, which when the min / and is taken we get UNKNOWN (i.e. when DNO = 3).