0

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.

3 Answers 3

1

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
        )
Sign up to request clarification or add additional context in comments.

Comments

0

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

SELECT ID 
INTO #TempTable 
FROM table

Comments

0

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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.