Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what do you mean by that statement? if the condition is true, what is it going to return?
what is select top 1 null?
is it something like selecting the records even if some columns have null values also in a row to prevent the omitting of that particular row?
kindly help me with your answers.
Posted
Comments
Abdul Samad KP 30-Apr-15 11:08am    
As Karthik said , it is just checking any rows are there in the table. There is nothing to do with null , you can use like IF EXISTS(select top 1 1 from table) also

If row(s) are present in the table it returns true else false
AFAIK no other logic behind, tested.
 
Share this answer
 
Karthik is right. This only checks if there are some rows in the table or not. It has the same effect as:
SQL
if exists(select * from table)

The author of that query just tried to be smart and optimize it by only selecting one row. But this is actually not needed because in both cases the query plan is exactly the same.
 
Share this answer
 
Comments
Karthik_Mahalingam 30-Apr-15 14:04pm    
yes,
initially i was wondered that there might be some other reason for this,but not -:) +5
Tomas Takac 30-Apr-15 14:43pm    
I checked it just to be sure but there is really no difference. I know before (version 2000?) this kind of things mattered, but definitely not in version 2014. Old habits are just hard to change I guess. :)
Karthik_Mahalingam 30-Apr-15 14:47pm    
:) of course

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900