我对EXISTS
子句有一个问题:我有一个使用它的查询,但使用了我从未见过的代码。
在子选择的WHERE
中,我看到这样的表达式:
WHERE
@var IS NULL
OR EXISTS(another subselect)
但这个变量不能与他的select和subselect进行链接。
这是怎么回事?
where @var is null
是布尔条件
如果@var
为null,则为true,否则为false。
or exists (select '' from table t
where t.id = s.id and date > '2012-12-1')
如果子查询至少存在一行,则返回true。
如果@var
不为空,则针对真实条件评估exists