• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

[PHP]Mysql troubles.

dawizman

New Member
Ok, I am having some troubles figuring out how the following would be done.

Here is what I am trying to do:

-Take the info from 1 table
-insert it into a new table, in the same DB, with the same columns.


Any help would be much appreciated.
 
You would really need to run two seperate querys

INSERT INTO table2 SELECT * FROM table1 WHERE info='whatever'

DELETE FROM table1 WHERE info='whatever'
 
so, say i wanna transfer the whole table over. would the following work:

mysql_query("INSERT INTO table2 SELECT * FROM table1 ");
mysql_query("DELETE FROM table1");
 
hmm, well if you want to transfer everything from one table to another it would be easier to just rename the table the data is currently in

ALTER TABLE table1 RENAME table2
 
mabye i'm misunderstanding but i can't see any reason why you would want to select everything from one table, place it into another and then delete it from the first :confused4 when the table can just be renamed.

yes you can select the entire table, i think what you have would work

and your second line a delete from table with no "where" clause would basically write over the entire table, with the same structure but no data

so make sure that's what you want to do
 
No, see, table 2 is like an archive, all the old data goes into it. Table 1 is where only the newest data goes. So, when new info is being entered into table 1, the old stuff is going to get moved to table 2.

Do you understand?
 
Back
Top