Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy data from one table to another new table in MySQL?

Tags:

copy

mysql

I want to copy data from one table to another in MySQL.

Table 1 (Existing table):

aid    
st_id
from_uid
to_gid
to_uid
created
changed
subject
message
link

Table 2 (New Table)

st_id
uid
changed
status
assign_status

I want to copy some fields of data from TABLE 1 into TABLE 2.

Can this be done using MySQL queries?

like image 656
Fero Avatar asked Oct 09 '22 07:10

Fero


1 Answers

This will do what you want:

INSERT INTO table2 (st_id,uid,changed,status,assign_status)
SELECT st_id,from_uid,now(),'Pending','Assigned'
FROM table1

If you want to include all rows from table1. Otherwise you can add a WHERE statement to the end if you want to add only a subset of table1.

like image 78
jdias Avatar answered Oct 11 '22 20:10

jdias