Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining INSERT SELECT with constants

Tags:

sql

I'm trying to insert records into a table where one of the columns comes from another table.

The other two columns are the same for each record.

All three columns are keys.

I'm trying this embedded INSERT SELECT which I see is not allowed?

INSERT INTO TABLE (COLUMN_A, COLUMN_B, COLUMN_C)
    VALUES (1,(SELECT COLUMN_NAME FROM TABLE) ,2)
like image 395
user1327418 Avatar asked Jun 12 '15 17:06

user1327418


1 Answers

Your syntax is off - this is the correct syntax for this:

Insert Into Table
        (Column_A, Column_B, Column_C)
Select  1, Column_Name, 2
From    OtherTable 
like image 55
Siyual Avatar answered Oct 21 '22 19:10

Siyual