【发布时间】: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
例如
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
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。
【讨论】: