SQL query select query

I have values ​​in temp table like this

ID
1
2
3

but know from employee table, i need to select values ​​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 binding gives me only one string value, in fact there is data for all identifiers

Is there anything wrong with the syntax I'm going to, pls let me know.

thnkas prince

+3
source share
3 answers

Try the following:

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

Or you can just join the two tables.

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

Why not just join?

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

You need to join the temp table with the employees table:

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

This should only return employees whose identifier is in the temp table.

0
source

All Articles