tags:

views:

22

answers:

3

Morning all, I'm running SQL Server and there are a whole lot of tables in there. I have taken one column from one of these tables using SELECT, and it gives me the list of IDs. I need to use these IDs as the lookup point to get the data for that ID from another table. Is it necessary that I do a CREATE TABE manouvre?

I was hoping I could just use the data returned from the original SELECT statement without having to set up a new table....

Cheers.

+1  A: 

You can use a where ... in construct to retrieve matching rows from the other table:

select  *
from    OtherTable
where   id in
        (
        select  id
        from    FirstTable
        )
Andomar
A: 

You can use a few options, but most typical would be to create a temp table.

SELECT ID 
INTO #TempTable 
FROM table
Dustin Laine
A: 

You can also use a inner join if you need additional values from the first table

select OtherTable.*, FirstTable.extrafield1, FirstTable.extrafield2
from OtherTable
inner join FirstTable on FirstTable.Id = OtherTable.FirstTableId 
Doggett