Sql server sql选择查询问题
我在temp表中有这样一个值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
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在临时表中的员工