Copy Data From One Table To Another AND Adding Add

2020-07-06 04:28发布

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.

标签: mysql
2条回答
家丑人穷心不美
2楼-- · 2020-07-06 05:04

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

查看更多
Animai°情兽
3楼-- · 2020-07-06 05:26
 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
查看更多
登录 后发表回答