Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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 server sql选择查询问题_Sql Server - Fatal编程技术网

Sql server sql选择查询问题

Sql server sql选择查询问题,sql-server,Sql Server,我在temp表中有这样一个值 ID 1 2 3 但从employee表中知道,我需要从temp表中选择值 declare @mStrvalue as varchar(100) select @mStrvalue =IDS from Temp_ID select * from employee where employee.emp_ID= @mStrvalue 现在这个状态只给了我1行值,实际上所有ID都有数据 我要讲的语法有什么错误吗,请告诉我 廷卡斯 王子为什么不加入呢 SELEC

我在temp表中有这样一个值

ID
1
2
3
但从employee表中知道,我需要从temp表中选择值

declare  @mStrvalue as varchar(100)
select   @mStrvalue =IDS from Temp_ID
select * from employee where employee.emp_ID= @mStrvalue 
现在这个状态只给了我1行值,实际上所有ID都有数据

我要讲的语法有什么错误吗,请告诉我

廷卡斯 王子

为什么不加入呢

SELECT 
   *
FROM employee 
   INNER JOIN Temp_ID ON employee.emp_ID = Temp_ID.ID
试试这个:

select * from employee where employee.emp_ID in (select IDS from Temp_ID);
或者你可以把这两个表连接起来

select *
  from employee inner join Temp_ID on employee.id = Temp_ID.IDS;

您需要将临时表与员工表联接:

    select e.*
      from employee e
inner join Temp_ID t on e.emp_id = t.ids
这应该只返回id在临时表中的员工