![](/img/trans.png)
[英]Select a column from one tbl and insert into another column in an other table
[英]Insert column from other table into another
我需要将其他表中的“日期”列添加到数据库中的另一个表中。
第一表:
id date
1 01/01/2010
2 02/01/2010
第二张表(我需要在其中插入“日期”):
id date
1
2
第二个表是我需要从第一个表中插入“日期”的地方,两个ID都相同。
目前,我所得到的是返回语法错误的查询:
INSERT INTO Table2 A (date)
SELECT date FROM Table1 B
WHERE A.id = B.id
我该如何解决?
我认为您想要update
:
update table2 a join
table1 b
on a.id = b.id
set a.date = b.date;
您需要确保该列存在于第二个表中。 如果不是这样,您可以使用诸如alter table table2 add column date date
类的方式将其alter table table2 add column date date
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.