SQL select null 的用法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4875745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
usage of select null?
提问by kamaci
I see that some examples uses select statement with null. When to use:
我看到一些示例使用带有 null 的 select 语句。何时使用:
select null from etc. etc.?
回答by Sachin Shanbhag
Select null is usually used in combination with EXISTS.
eg:-
IF EXISTS( select null from ...)
Select null 通常与 EXISTS 结合使用。
例如:-
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)
如果选择查询中有记录,则将 Exists 状态设置为 true。检查此链接,其中对 select null with Exists 的使用有一些有趣的评论:SQL SERVER- IF EXISTS(Select null from table) vs IF EXISTS(Select 1 from table)
回答by Cyril Gandon
Linq to SQL do this sort of thing :
Linq to SQL 做这样的事情:
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.
当我不需要数据时,它可以防止带来数据,而只是存在状态。