I see that some examples uses select statement with null. When to use:
select null from etc. etc.?
The IS NULL condition is used in SQL to test for a NULL value. It returns TRUE if a NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.
In terms of the relational database model, a NULL value indicates an unknown value. If we widen this theoretical explanation, the NULL value points to an unknown value but this unknown value does not equivalent to a zero value or a field that contains spaces.
A null value indicates a lack of a value, which is not the same thing as a value of zero. For example, consider the question "How many books does Adam own?" The answer may be "zero" (we know that he owns none) or "null" (we do not know how many he owns).
Select null is usually used in combination with EXISTS.
eg:-
IF EXISTS( select null from ...)
It sets up the Exists status as true if there are records in the select query. Check this link which has some interesting comments on the usage of select null with Exists: SQL SERVER- IF EXISTS(Select null from table) vs IF EXISTS(Select 1 from table)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With