Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 不适用于多个select语句_Sql_Sql Server_Tsql - Fatal编程技术网

Sql 不适用于多个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

我需要执行以下操作,但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 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);