开发者

How to import some data from one table to another(MYSQL)

开发者 https://www.devze.com 2023-04-11 00:12 出处:网络
I am working on a projects. There are two tables, users and mileage_registrants. A module of our website needs users to do another registration except the one for main access to our website. Now the p

I am working on a projects. There are two tables, users and mileage_registrants. A module of our website needs users to do another registration except the one for main access to our website. Now the problem is that our clients don't want to do such kind of registration and I don't want to change the whole architecture of the module. So what I want to do is to import user_id from table users to mileage_registrants and set other fields as default or NULL.

The structure of table mileage_registrants is like:

'id`, `user_id`, `team_id`,  `team_leader`, `building_name`, `department`, `phone_ext`, `party_registered`, `creation_date`.

There are more than 1000 users needed to b开发者_Go百科e done. It is horrible to insert the data one by one. Is there any solution that can quickly get this done? thanks


Getting data from one table to another can be done like this quite easy.

INSERT INTO table1 (column1,column2) SELECT oldcolumn1,oldcolumn2 FROM table2 

(optionally with a where clause)

Take a look at the documentation: http://dev.mysql.com/doc/refman/5.1/en/insert-select.html


Try this:

insert into mileage_registrants (`user_id`, `team_id`,  `team_leader`, `building_name`, `department`, `phone_ext`, `party_registered`, `creation_date` ) 
SELECT user_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL from users
0

精彩评论

暂无评论...
验证码 换一张
取 消