简体   繁体   English

将3列插入到表中,其中只有2列来自另一个表

[英]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.

相关问题 选择表中的列,其中表名是从另一个表中选择的,并将它们连接起来,只选择特定的列 - Selecting columns in a table where table name is selected from another table and concatenate them selecting only specific columns 从具有不同列的另一个表插入到一个表中 - insert into a table from another table with different columns 将列从一个表插入到另一个表的过程 - procedure to insert columns from one table to another 插入其他表格中的列以及文字 - Insert columns from another table as well as text 从表插入到另一个带有附加列的PHP - insert from table to another with additional columns PHP 从表中删除行,其中列来自另一个表 - delete rows from table where the columns are from another table SQL将一个表中的多行插入另一个表的列中 - SQL insert multiple rows from one table into columns on another table 从1个表中选择多个列插入另一个表的多行 - select mutiple columns from 1 table insert into multiple rows of another table 将一个表中的行插入到具有特定模式的另一个表的列中 - Insert rows from one table to columns of another table with specific pattern 将特定的列从架构表插入到Postgres中的另一个架构表 - Insert specific columns from schema table to another schema table in Postgres
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM