SQL 将另一个表中选定的列插入到表中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23684829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:53:23  来源:igfitidea点击:

Insert into table the selected columns from another table

sqlinsert

提问by Maxim Alexandru

What query would insert the selected columns, for a desired value, from a table into another table?

什么查询会将选定的列插入到另一个表中,以获得所需的值?

Before Query

查询前

table1=>Colums(A,B,C)
  row1(a,b,1)
  row2(c,d,0)
  row3(e,f,1)

table2=>Columns(id,A,B)

After Query

查询后

table1 is unchanged.

table2(id,A,B)
  row1(id,a,b)
  row2(id,e,f)

I need to insert in table2 all the rows from table1 where 'C=1', C may equal 1 in multiple records.

我需要在 table2 中插入 table1 中的所有行,其中 'C=1',C 在多个记录中可能等于 1。

回答by T McKeown

INSERT INTO TABLE2(A,B,C)
SELECT A,B,C
FROM TABLE1
WHERE C = 1

回答by rbedger

you can also select all the columns into a table without creating it first:

您还可以将所有列选择到一个表中,而无需先创建它:

SELECT *
INTO TABLE2
FROM TABLE1
WHERE C=1