Copying Data from One Table to Another in MySQL Using Queries
Copying data between tables in MySQL is a common task for data management and manipulation. Let's delve into how this can be achieved.
In this scenario, you have two tables: Table 1 (an existing table) and Table 2 (a new table). Your goal is to copy data from specific fields of Table 1 into Table 2.
To accomplish this using MySQL queries, you can utilize the following INSERT statement:
INSERT INTO table2 (st_id, uid, changed, status, assign_status) SELECT st_id, from_uid, now(), 'Pending', 'Assigned' FROM table1
This query will populate Table 2 with the following data from Table 1:
By default, this query will copy all rows from Table 1. However, you can add a WHERE clause to specify a condition if you want to copy only a subset of rows.
The above is the detailed content of How to Copy Data from One MySQL Table to Another Using Queries?. For more information, please follow other related articles on the PHP Chinese website!