Search code examples
mysqlsql-serverinserttemp-tables

Insert into temporary table mysql


select t.* 
into #temp 
from 
( 
select 'a' as a 
union all 
select 'b' as a 
) as t 

select * from #temp 

drop table #temp 

i usually do this on SQL server wherein i create a temporary table. the syntax "into #temp" creates a non-physical table on the DB, while "into temp" will create a physical table on the DB.

My problem in MySQL is to convert the above MSSQL statement. What i want is to create is a temporary table that is not physically created on the DB. Do we have this feature in MySQL?


Solution

  • In MySQL, you would use create temporary table as:

    create temporary table temp as
        select 'a' as a 
        union all 
        select 'b' as a ;