DarkReaper Posted August 21, 2006 Share Posted August 21, 2006 Lets suppose we have 2 tables with same structure, i want to move row with id=N from table1 to table2. How do i do that? I hope there is a simple way, because selecting from 1 -> inserting in 2 does not appear to be a good idea :) Quote Link to comment https://forums.phpfreaks.com/topic/18193-moving-rows-from-table1-to-table2/ Share on other sites More sharing options...
shoz Posted August 21, 2006 Share Posted August 21, 2006 [quote author=DarkReaper link=topic=105055.msg419408#msg419408 date=1156167151]Lets suppose we have 2 tables with same structure, i want to move row with id=N from table1 to table2. How do i do that? I hope there is a simple way, because selecting from 1 -> inserting in 2 does not appear to be a good idea :)[/quote][code]INSERT INTO table 2 SELECT * FROM table1 WHERE id=$idnum[/code]If by "move" you mean to remove the entry from table1 as well, then do a DELETE afterwards[code]DELETE FROM table1 WHERE id = $idnum[/code]If the tables have a PRIMARY KEY and you're fine with overwriting a previous entry with the same id then you should change the INSERT to a REPLACE.[code]REPLACE INTO table2 SELECT * FROM table1 WHERE id = $idnum[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18193-moving-rows-from-table1-to-table2/#findComment-78087 Share on other sites More sharing options...
DarkReaper Posted August 21, 2006 Author Share Posted August 21, 2006 Thanks! These examples will do the job :) Quote Link to comment https://forums.phpfreaks.com/topic/18193-moving-rows-from-table1-to-table2/#findComment-78108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.