【发布时间】:2012-10-23 05:34:57
【问题描述】:
如何在sql中选择一个列插入到另一个表中的现有列中?
【问题讨论】:
-
您能否重新表述一下这个问题 - 目前尚不清楚您是想将一个值插入一个从另一个表中选择的表中,还是完全插入其他表中。
-
您应该详细说明您的实际问题。如果这个特定场景的语法是你的问题,你应该只是 google!!
如何在sql中选择一个列插入到另一个表中的现有列中?
【问题讨论】:
查询是mysql
insert into existing_table (column_name) select column_name from another_table;
【讨论】:
首先,两列的 schema 应该相同,即如果您尝试从中复制值的列包含 DateTime 值,则目标列也应该接受 DateTime 值。
那么答案就是:
insert into targetTable (targetColumn) values ( select sourceColumn from sourceTable where predicate )
【讨论】:
你可以试试这个
insert into table1 (column)
values (select column from table2 where condition)
【讨论】: