Categories
mysql

MYSQL: How to copy an entire row from one table to another in mysql with the second table having one extra column?

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:

  1. How do I get around this?
  2. How do I add the value for the additional date column (CURRENT_DATE()) in table2 within this same statement?

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;

See T.J. Crowder’s comment