Can anyone explain me about this SQL Query
S开发者_StackOverflow社区elect Null as Empty from (select * from TblMetaData)
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
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
.
It looks like the result of one of two possible situations:
- The developer was getting paid per line, and threw in that query. It was probably originally structured to take more than one line.
- The developer was incompetent and this was the only way they could think of to generate a bunch of null values.
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.
It often used in this expression
select * from TableA where exists
(select null from TableB where TableB.Col1=TableA.Col1)
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
精彩评论