This is table 1 which i want to copy its data and paste into another table. I mean, I want to copy one table data and paste into another table in PHP with MYSQL.
My first MYSQL database table -
My second MYSQL database table.
How can I copy one table data into another table via PHP and MYSQL database table.
To copy one MySQL table data in another table MYSQL query is to be used. To copy the data from one table to another table, you have to perform the query of MYSQL in such a way that your problem is solved. In the query of MYSQL, you have to select the data from a table and You have to copy (insert) the other table. To copy the data table of the Msql table, you have to do the following query to MYSQL.
INSERT INTO table 2 SELECT * FROM table 1 WHERE ...
INSERT INTO table 2
SELECT * FROM table 1 WHERE ...
Insert into table 2 - Insert the data into table 2
SELECT * FROM table 1 WHERE ..- Select the data from table From where do you want to copy. 1.
You have to need to use this MYSQL query to perform the copy operation one table to another.
I have a reference for you.
Copy one table data into another table is pretty simple using the MYSQL query. First of all, understand the thing because you want to select the data and insert into another MYSQL database table using PHP. It's not a big deal, you can modify query according to your need.
Use the below query to insert and select data.
INSERT INTO table2SELECT * FROM table1 ;
INSERT INTO table2
SELECT * FROM table1 ;
The table is another table in which you want to insert the data from table one in PHP. The table1 specifies the table from which you want to select data and paste (insert) data into another table.
You can use Where clause with the select query.
INSERT INTO table2SELECT * FROM table1 WHERE ;
INSERT INTO table2
SELECT * FROM table1 WHERE ;
WHERE clause helps to select the specific id-data or other. You can change according to your need.
If you want to insert data from another table, you have to check and specify the columns too. The MYSQL database table layouts can be different, you should understand this concept and specify the columns (fields )
INSERT INTO table2(column1, column1, column1)
SELECT column5, column7, column8 FROM table1 WHERE id = 1