简体   繁体   中英

mysql copying specific columns from one database table to another using php

I'm trying to create a cron job through php that has mysql queries (NOT for backup purposes), and want it to copy two specific columns from a table from one database to another (the two databases are on the same server, but has different connections).

I've tried

    insert into newDB.your_table select * from oldDB.your_table;

but that didn't work for some reason and i want it to be specific to 2 columns only.

Any help, code, example, tutorial would be much much appreciated.

Thank you for time.

As shown on this page http://dev.mysql.com/doc/refman/5.7/en/insert-select.html

To selectively copy only specific columns from one table to another, the SQL:

INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;

So for your example: INSERT INTO newDB.some_table (id, value) SELECT id, value FROM oldDB.some_other_table;

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