简体   繁体   中英

mysql insert into table select from another database

I have a table named user in database named client . user has the structure as follows:

`fkey`(varchar(100)) | `status`(enum('1','0'))

I have another database named employees with a table named employee It has a cloumn named emailid which has all the data I need.

I want all the emailid column data from employees.employee to be inserted in client.user at fkey column.there is another column status in client.user which needs to be set as 1 .How do I create a query for this.

This is my query but it is wrong.

insert into client.user (`fkey`,`status`) select `emailid` from employees.employee,'1';

Definitely it's wrong syntax . It should be

Insert into client.user (fkey,status) select `emailid`, '1' from employees.employee 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM