usage of select null?

57,133

Solution 1

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)

Solution 2

Linq to SQL do this sort of thing :

Select * 
From Foo f 
Where Exists
(   
    Select null 
    From Bar b 
        on b.fooId = f.id
)

It prevents to bring data when I don't want data, but just the exist status.

Share:
57,133
kamaci
Author by

kamaci

Updated on November 24, 2020

Comments

  • kamaci
    kamaci over 3 years

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

    select null from etc. etc.?