truthseeker
truthseeker

Reputation: 2265

How to save select query results within temporary table?

I need to save select query output into temporary table. Then I need to make another select query against this temporary table. Does anybody know how to do it?

I need to make this on SQL Server.

Upvotes: 51

Views: 151167

Answers (3)

Yas
Yas

Reputation: 5471

In Sqlite:

CREATE TABLE T AS
SELECT * FROM ...;
-- Use temporary table `T`
DROP TABLE T;

Upvotes: 2

John Saunders
John Saunders

Reputation: 161773

You can also do the following:

CREATE TABLE #TEMPTABLE
(
    Column1 type1,
    Column2 type2,
    Column3 type3
)

INSERT INTO #TEMPTABLE
SELECT ...

SELECT *
FROM #TEMPTABLE ...

DROP TABLE #TEMPTABLE

Upvotes: 45

Eric K Yung
Eric K Yung

Reputation: 1784

select *
into #TempTable
from SomeTale

select *
from #TempTable

Upvotes: 66

Related Questions