anujgarg Posted April 23, 2010 Share Posted April 23, 2010 Hi, I am writing a data migration PHP script. I have a table with following structure: id parent_id 1 0 2 0 3 2 4 3 This table data needs to be migrated in a different table that already contains some record. So, the ids will be different here (lets say following): id parent_id 10 0 11 0 12 2 13 3 But, as we are seeing the parent_id is same in new table. Here comes my problem. I want to change the parent_id according to modified (new) id in new table. How can it be possible? Please suggest... All suggestions will be highly appreciated. Regards, Anuj Link to comment https://forums.phpfreaks.com/topic/199465-data-migration-script/ Share on other sites More sharing options...
anujgarg Posted April 23, 2010 Author Share Posted April 23, 2010 More specifically, the new table should be look like: id parent_id 10 0 11 0 12 11 13 12 Link to comment https://forums.phpfreaks.com/topic/199465-data-migration-script/#findComment-1046945 Share on other sites More sharing options...
cags Posted April 23, 2010 Share Posted April 23, 2010 This is probably not the best way and is purely hypothetical. Perhaps you could port it over with an extra column for old_id then run a query along the lines of... UPDATE table t1 SET parent_id = (SELECT id FROM table t2 WHERE t2.old_id = t1.parent_id) You could then drop the old_id column if it's no longer required. Link to comment https://forums.phpfreaks.com/topic/199465-data-migration-script/#findComment-1046948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.