How to import some data from one table to another(MYSQL)
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
精彩评论