Sql 不适用于多个select语句
我需要执行以下操作,但T-SQL有一个问题,就是如何在NOT IN中有多个select语句Sql 不适用于多个select语句,sql,sql-server,tsql,Sql,Sql Server,Tsql,我需要执行以下操作,但T-SQL有一个问题,就是如何在NOT IN中有多个select语句 select * from table1 where ParamID not in (select paramid from tbl2 or select paramid from tbl3 or select paramid from tbl3) 我得到一个错误:select附近的语法不正确 有没有其他方法来做我想做的事 使用UNION,如: 试试这个 select * from
select * from table1 where ParamID not in
(select paramid from tbl2
or
select paramid from tbl3
or
select paramid from tbl3)
我得到一个错误:select附近的语法不正确
有没有其他方法来做我想做的事 使用UNION,如:
试试这个
select * from table1 where ParamID not in
(select paramid from tbl2
union all
select paramid from tbl3
union all
select paramid from tbl3)
我将使用“不存在”来代替:
select t.*
from table1 t
where not exists (select 1 from tbl2 where paramid = t.paramid) or
not exists (select 1 from tbl3 where paramid = t.paramid);
每个where子句条件必须具有等式的两侧。现在你有1个在左边,3个在右边。ParamID不在A、B、C中,您可以在ParamID不在且ParamID不在且ParamID不在的情况下使用。是否存在联盟。但是为什么要从tbl3检查两次paramid?那是打字错误吗?
select t.*
from table1 t
where not exists (select 1 from tbl2 where paramid = t.paramid) or
not exists (select 1 from tbl3 where paramid = t.paramid);