It is unclear if you only want to know the SQL commands or if you want to create the connection with a PHP script.
Therefore, in a general way,
First delete existing data:
DELETE FROM TAB2;
Then run INSERT INTO TAB2 (SELECT * FROM TAB1);
You can do this using a Mysql front-end like Phpmyadmin.
*illustrative image
You cannot do your queries at the same time as Mysql prevents multiple queries by default. It is possible to change this pattern but implies security issues.
Important to note that if you are only going to replace the data from one table with the data from another table you could just apply REPLACE INTO, without using the truncate
or of delete
.
REPLACE INTO TAB2 (SELECT * FROM TAB1)
That’s all it takes.
But for a specific case where you want to clean "traces" from the table TAB2
that do not exist in TAB1
, it is even better to exclude everything before proceeding with the INSERT
.
I don’t know anything about
php
so I’ll let someone else help– Bruno Costa
Pk André. If you enter the code you have right now your question will be more accepted by the community.
– Bruno Costa