Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert into a table from temp table?

I already have values in a temp table and I want to insert it into my table.

I follow this syntax

IF NOT EXISTS (SELECT 1 FROM ABC abc JOIN #Temp t ON abc.ID = t.ID)

insert into MyTable(Id,Name)
select values (t.ID, t.Name)
From t

I have just the name t as an alias I created in a condition before this insert.

Is this correct? Some people use @ etc. I am confused.

like image 730
Jasmine Avatar asked Oct 14 '25 16:10

Jasmine


1 Answers

Correct syntax:

insert into MyTable(Id,Name)
select t.ID, t.Name
From #temp t

Always read manual

like image 93
Lukasz Szozda Avatar answered Oct 17 '25 04:10

Lukasz Szozda