I've got a sql database with these fields: database 1 id | title | keywords | description | active | parentId I made a text file dump of this compete database, now I want to manually insert this data into database 2 with an SQL query in phpmyadmin running INSERT INTO `cat` VALUES (id, 'title', 'keywords ', 'description ', 'active ', parentId); , the only problem is that the structure of the other database is totally different: database 2 id | parentId | title | description | active | frontpage | lastUpdate Is there an easy way to insert the old data from database 1 into database 2 into the right fields? There are over 1000 entries in this database. I'm not really familiar with sql databases, tried some things but it didn't work. If the fields keywords is lost that doesn't matter, not really important. Thanks in advance.
When I migrate tables I write PHP code to do it. First select all from the old table. Loop through each record. Re-jig the order and add 'NULL' or whatever other default value for the new fields and then INSERT into the new table for each row.
You can specify the ordering of the fields in the SQL e.g. INSERT INTO `cat` (id, parentId, title, description, active) VALUES (id, parentId, 'title', 'description ', 'active '); Code (sql):
Thanks dct! Got it working. It was after all quite simple, thanks for pointing me in the right direction.
From one table to the other, you will need this: Mysql - INSERT ... SELECT http://dev.mysql.com/doc/mysql/en/INSERT_SELECT.html With INSERT ... SELECT, you can quickly insert many rows into a table from one or many tables. For example: INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;