SQL - 混合存在'和'和'或'

时间:2012-07-09 11:21:13

标签: sql hibernate

我无法获得可行的查询,其中我可以拥有多个必需记录,并且存在单个“两个中的一个”。

我正在使用Hibernate,hql,sql显然不会有根本的不同,但这意味着我不能使用完全连接(因此很尴尬)。

我基本上想要什么,但不能因为我不知道如何混合内部和外部存在的呼叫:

select 1
from  application
where
application = ? and
exists (select 1 from x where ...) and
exists (select 1 from y where ...) and
exists ((exists (select 1 from Document where ...))
or 
(exists (select 1 from QA answer where ...)))

所以我需要x& y,但只要存在1,就可以接受文件或质量保证。

1 个答案:

答案 0 :(得分:2)

这样的东西?

select 1
from  application
where
application = ? and
exists (select 1 from x where ...) and
exists (select 1 from y where ...) and
(
    exists (select 1 from Document where ...)
    or 
    exists (select 1 from QA answer where ...)
);