【问题标题】:Can in line views in oracle sql contain "not in" clause in the query?oracle sql中的行内视图可以在查询中包含“not in”子句吗?
【发布时间】:2019-11-21 01:34:21
【问题描述】:

例如

select *
from t1 
inner join (select * from t2 where t2.id not in (select ID from t2 where city="Paris"))

我尝试在 Google 上搜索。有很多示例,但没有一个使用 not in。另外,内嵌视图没有指定限制。

【问题讨论】:

    标签: sql oracle subquery derived-table


    【解决方案1】:

    Oracle 在FROM 子句“内联视图”中调用子查询。

    这些是通用的SELECT 查询。它们可以包含带有子查询的NOT IN。您的查询的问题是缺少ON 子句以及对字符串常量使用双引号:

    select *
    from t1 inner join
         (select *
          from t2
          where t2.id not in (select ID from t2 where city = 'Paris')
    ---------------------------------------------------------^ single quotes
         ) t2
         on t1.? = t2.?
    -----^ on clause
    

    注意:我不鼓励您将NOT IN 与子查询一起使用,因为如果任何 返回值为NULL,它们将无法按预期工作。 (如果是这种情况,则不返回任何行。)

    我建议改用NOT EXISTS

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      相关资源
      最近更新 更多