This question is out of a databases exam i was looking at, so it might be nothing one can ever use in a real situation…
What output does the following valid SQL statement produce? Explain your answer!
SELECT (NULL = NULL);
I can easily produce the output of the statement, which is
school=> select (null = null); ?column? ---------- (1 row)
in psql 8.4.11, but how and why this is the answer i don’t know… I would have guessed it tries to evaluate the expression inside the brackets and comes up with true/false but apparently it doesn’t.
Any hints on why it behaves like it does?
Thanks
NULLstands for “Unknown Value”. It is not known whether a value is true or false or anything else.So, when comparing two unknown values, what would the answer be? Is UnknownA equal to UnknownB?
Answer? Unknown…
Here is an example for SQL Server:
The only thing that gets printed:
IS