Reputation: 101
I have a temp table and a regular table in my database. The column name and types are identical, except the regular table has an extra field. I am trying to write a query that copies the information from the temp table into the regular table and adds data into the addition field all in one query.
I understand how to copy columns from one table to another (e.g. INSERT INTO TABLE 1 (col 1, etc..) SELECT TABLE2), but how do i do this AND then add in a the value for the new field?
Thanks for your help.
Upvotes: 9
Views: 10777
Reputation: 63
If you want your values
INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *,concat('".$value."') as value1 from TABLE2
Date means just put now()
INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *,now() from TABLE2
Upvotes: 2
Reputation: 55876
INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *, NULL from TABLE2
or
INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *, the_default_date_here from TABLE2
Upvotes: 10