MYSQL:如何在mysql中将整个行从一个表复制到另一个表,而第二个表又增加一列? [英] MYSQL: How to copy an entire row from one table to another in mysql with the second table having one extra column?
本文介绍了MYSQL:如何在mysql中将整个行从一个表复制到另一个表,而第二个表又增加一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了一列外,我有两个结构相同的表.表2还有另外一列,我将在其中插入CURRENT_DATE()
I have two tables with identical structure except for one column... Table 2 has that additional column in which i would insert the CURRENT_DATE()
我想将所有值从table1复制到table2.
I would like to copy all the values from table1 to table2.
如果我使用
INSERT INTO dues_storage SELECT * FROM dues WHERE id=5;
它抛出一个错误,指出列数的差异.
it throws an error pointing out to the difference in the number of columns.
对此我有两个问题:
- 我该如何解决?
- 以及如何在同一条语句的表2中添加附加日期列(CURRENT_DATE())的值?
推荐答案
从Zed优化答案并回答您的评论:
To refine the answer from Zed, and to answer your comment:
INSERT INTO dues_storage
SELECT d.*, CURRENT_DATE()
FROM dues d
WHERE id = 5;
请参见T.J.人群的评论
这篇关于MYSQL:如何在mysql中将整个行从一个表复制到另一个表,而第二个表又增加一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文