TAGS :Viewed: 7 - Published at: a few seconds ago

[ Can anyone explain me about this SQL Query ]

Select Null as Empty from (select * from  TblMetaData)

Answer 1


Looks like, it is trying to get null rows for the same number of rows in tblMetaData.

EDIT: This could be written as
SELECT Null AS Empty FROM tblMetaData

Answer 2


It will yield a result set with one column named Empty which only contains NULL values. The number of rows will be equal to the number of rows available in TblMetaData.

Answer 3


It looks like the result of one of two possible situations:

  1. The developer was getting paid per line, and threw in that query. It was probably originally structured to take more than one line.
  2. The developer was incompetent and this was the only way they could think of to generate a bunch of null values.

Answer 4


The query returns a null value from each line of the table, so the only real information in the result is the number of records in the table.

This can of course be found out a lot more efficently using:

select count(*) as Count from TblMetaData

It's possible that the developer was not at all aware of the count aggregate (or how to search the web) and tried to get the number of records while making the result as small as possible.

Answer 5


it can be used to give the number of rows in the table TblMetaData with the column's name denoting the first letter of empty(in this case only). like suppose you gave

Select Null as Empty from (select * from TblMetaData)

so it will give E

n rows selected here n is the number of rows in the table.

suppose you gave

Select Null as XYZ from (select * from TblMetaData) then it would be same but the column's name would change like X

n rows selected

Answer 6


It often used in this expression

select * from TableA where exists 
(select null from TableB where TableB.Col1=TableA.Col1)