error:当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式

体育网编2023-07-08 09:171920
-- 报错代码
select top 3 *
	from emp
	where empno not in (select top 3 * from emp order by sal desc)
	order by sal desc

错误原因:如果要用in,后面 SELECT 必须能只能由一个列组成

-- 更正
select top 3 *
	from emp
	where empno not in (select top 3 empno from emp order by sal desc)
	order by sal desc;

如果是多列

select * from A where exists(
select b from tab where A.b = tab.B and A.b2 = tab.B2)

评论区