bachx Posted April 21, 2007 Share Posted April 21, 2007 I have some data in table, and I want to move that data (certain fields only) into another table in the same DB. I'm wondering how can this be done? Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/ Share on other sites More sharing options...
per1os Posted April 21, 2007 Share Posted April 21, 2007 $sql = "INSERT INTO table_name (`col1`, `col2`) VALUES(SELECT col1,col2 FROM table_name2 WHERE CONDITION=TRUE);"; Something like that may work, not sure. Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/#findComment-234753 Share on other sites More sharing options...
bachx Posted April 21, 2007 Author Share Posted April 21, 2007 Negative. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT x1,x2 FROM table1 WHERE CONDITION=TRUE)' at line 1 Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/#findComment-234763 Share on other sites More sharing options...
per1os Posted April 21, 2007 Share Posted April 21, 2007 http://dev.mysql.com/doc/refman/4.1/en/insert-select.html INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100; $sql = "INSERT INTO table_name (`col1`, `col2`) SELECT col1,col2 FROM table_name2 WHERE CONDITION=TRUE;"; Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/#findComment-234768 Share on other sites More sharing options...
bachx Posted April 21, 2007 Author Share Posted April 21, 2007 That did it. Thanks Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/#findComment-234775 Share on other sites More sharing options...
bachx Posted April 21, 2007 Author Share Posted April 21, 2007 Alright. I have another question. I want to do the same exact thing, but instead of inserting new values, I want it to update the current data in the new table. Anyone? Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/#findComment-234873 Share on other sites More sharing options...
bachx Posted April 22, 2007 Author Share Posted April 22, 2007 Anyone can answer my last question? I'll be grateful. Link to comment https://forums.phpfreaks.com/topic/48030-mysql-how-to-copymove-values-from-one-table-into-another/#findComment-235015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.