【发布时间】:2020-04-13 15:11:26
【问题描述】:
select *
from emp
where
(select salary from dual) in (select salary from employees);
EMP 表具有与表EMPLOYEES 相同的 107。这里select salary from dual 应该在 where 子句中产生错误,但它不会。如何?
另一方面,它在 SQL Developer 中返回行,而不是在 sqlplus 中。为什么?
【问题讨论】:
-
不,如果'select Salary from dual'只返回1行&列,则不会抛出错误,如果返回的值存在于“select Salary from employees”中,将返回emp表中的所有行.如果该值不存在,则不会返回任何行
-
但是salary不是表dual的有效标识符,它不会返回任何行。
-
@AmanSinghRajpoot 正如 Littlefoot 的回答中指出的那样,鉴于上下文,该子查询中的
salary是对emp.salary的有效引用。这称为标量子查询。对于emp中的每一行,子查询将从该行返回salary的值。 -
没关系,让我把你的查询改写成这样 -> select * from emp where '1000' in (select Salary from employees);这可能对你更有意义
-
是的,非常感谢。