【发布时间】:2020-02-13 08:22:18
【问题描述】:
我想将 table1 中的列复制到 table2 中,并在 table2 中添加一些列。
虽然我知道语法:
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
但是如何在 table2 中添加额外的列数据?
我已经尝试过这种方法,但它给出了语法错误:
// first storing the desired data from table1 into a temporary table
CREATE TEMPORARY TABLE temp_table
select column1, column2, column3 from table1
where condition;
// then placing the selected columns into table2
INSERT INTO table2 (col1, col2, col3,col4) values (
SELECT column1 FROM temp_table,
SELECT column2 FROM temp_table,
SELECT column3 FROM temp_table,
'Additional Value'
);
【问题讨论】:
标签: mysql sql database sql-insert