[英]insert 3 columns into a table where only 2 columns are from another table
I wish to do something like this: 我希望做这样的事情:
INSERT INTO table2
(col1, col2, col3 = 'constant literal')
SELECT col1, col2
FROM table1;
So col1 and col2 are copied from table1 to table2, but col3 is set to be a constant value I want. 因此col1和col2从table1复制到table2,但是col3设置为我想要的常数。 The code above does not work. 上面的代码不起作用。 so how do i do this? 那我该怎么做? I don't want set a default value to col3 by changing the schema. 我不想通过更改架构将默认值设置为col3。
I am using sqlite3 if relevant. 如果相关,我正在使用sqlite3。
INSERT INTO table2 (col1, col2, col3)
SELECT col1, col2, 'constant literal'
FROM table1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.