我有两个表,table1
有2列,table2
有3列。
我想将table1 col1 and table1 col2
的值插入到一列的table2中。
以下是table1
的数据:
╔════════╦════════╗
║ Col1 ║ Col2 ║
╠════════╬════════╣
║ Value1 ║ Value2 ║
╚════════╩════════╝
将其插入table2
行:例如
╔════════╦
║ Value1 ║
╠════════╣
║ Value2 ║
╚════════╝
如何使用SQL执行此操作?
答案 0 :(得分:0)
如果要将每个复制在不同的行中,请使用:
INSERT INTO table2 (col1, col2)
SELECT col1, col2 FROM table1;
或逐一
INSERT INTO table2 (col1)
SELECT col1 FROM table1;
INSERT INTO table2 (col2)
SELECT col2 FROM table1;
如果要在同一行中连接,请使用
INSERT INTO table2 (col3)
SELECT col1 + col2 FROM table1;
OR
INSERT INTO table2 (col3)
SELECT col1 || col2 FROM table1;