开发者

sql select query issue

开发者 https://www.devze.com 2023-03-05 12:34 出处:网络
i have an values in temp开发者_运维技巧 table like this ID 1 2 3 but knowfrom employeetable i needto select values based from temp table

i have an values in temp开发者_运维技巧 table like this

ID
1
2
3

but know from employee table i need to select values based from temp table

declare  @mStrvalue as varchar(100)
select   @mStrvalue =IDS from Temp_ID
select * from employee where employee.emp_ID= @mStrvalue 

Right now this staement is giving me only 1 row value actually there is data present for all the ids

is there anything wrong in th e syntax that i am going, pls let me know.

thnkas prince


Try this:

select * from employee where employee.emp_ID in (select IDS from Temp_ID);

Or you could just join the two tables.

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


Why not just join?

SELECT 
   *
FROM employee 
   INNER JOIN Temp_ID ON employee.emp_ID = Temp_ID.ID


You will want to join the temp table with the employee table:

    select e.*
      from employee e
inner join Temp_ID t on e.emp_id = t.ids

This should return only employees whose id's are in the temp table.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号