[oracle]SQL 错误标志 (单行子查询返回多个行

标签: sql Oracle
发布时间: 2017/4/14 23:53:47
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我得到了这个"单行子查询返回多个行"

和我的查询是

Select contact_ID from contact where (

Select b.Contact_ID from company a, contact b where a.Company_ID =  b.Company_ID 
and a.IS_ACTIVE <> 'N' and b.IS_ACTIVE <> 'N'
and a.CREATED_DATE >= '01-Jun-2013') =
(
Select b.Contact_ID from company a, contact b where a.Company_ID =  b.Company_ID 
and a.IS_ACTIVE <> 'N' and b.IS_ACTIVE <> 'N'
and a.CREATED_DATE < '01-Jun-2013');

我不知道为什么这不工作。请你帮帮我

解决方法 1:

试试这个

    Select contact_ID from contact where Contact_ID in 
        (
         Select b.Contact_ID from company a 
         inner join contact b 
         on  a.Company_ID =  b.Company_ID 
         where a.IS_ACTIVE <> 'N' and b.IS_ACTIVE <> 'N'
         and a.CREATED_DATE >= '01-Jun-2013' 
         ) ;

编辑︰

没有更简单 IN 子句。

     Select b.Contact_ID from company a 
     inner join contact b 
     on  a.Company_ID =  b.Company_ID 
     where a.IS_ACTIVE <> 'N' and b.IS_ACTIVE <> 'N'
     and a.CREATED_DATE >= '01-Jun-2013' ;
赞助商