MYSQL: How to copy an entire row from one table to another in mysql with the second table having one extra column?
mysql
Solution
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;
Be VERY CAREFUL doing this. It does work, but it assumes the order of columns in the two tables is identical; it does not match by column name, and does try to coerce values to fit, which can cause unexpected results. Now, if your development structure assures the column orders are identical bar the last column, it's a convenient and straightforward way to do it, but the caveat is important.
Problem
I have two tables with identical structure except for one column... Table 2 has an additional column in which I would insert the CURRENT_DATE() I would like to copy all the values from table1 to table2. If I use ``` INSERT INTO dues_storage SELECT * FROM dues WHERE id=5; ``` it throws an error pointing to the difference in the number of columns. I have two questions: - How do I get around this? - How do I add the value for the additional date column (CURRENT_DATE()) in table2 within this same statement?