Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

usage of select null?

Tags:

sql

null

select

I see that some examples uses select statement with null. When to use:

select null from etc. etc.? 
like image 357
kamaci Avatar asked Feb 02 '11 14:02

kamaci


People also ask

Can we SELECT NULL values in SQL?

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.

Why do we use NULL value in a table?

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.

What is the use of NULL value give example?

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).


1 Answers

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)

like image 195
Sachin Shanbhag Avatar answered Sep 30 '22 19:09

Sachin Shanbhag