如何在Mysql上将一个表的字段复制到另一个表?

时间:2016-04-29 05:58:05

标签: mysql sql sql-server

我有一个名为 college 的数据库和两个名为 student student Personal details的表,学生表包含stud.Name, dept, address1,address2,address3。现在,我觉得address1, address2 and address3字段值移至 student Personal details (包含相同的字段)表。执行此操作的SQL查询是什么?

2 个答案:

答案 0 :(得分:1)

使用insert - select,查询如下,根据您的实际字段进行更正

insert into studentPersonaldetails (address1, address2, address3) 
select address1, address2, address3 from student 
where student.name = studentPersonaldetails.name

答案 1 :(得分:0)

更新collegestudentcollegestudent personal detailscollegestudentaddress1 = collegestudent personal detailsaddress1collegestudentaddress2 = collegestudent personal detailsaddress2collegestudentaddress3 = collegestudent personal detailsaddress3 哪里 collegestudentid = collegestudent personal detailsid;

我认为id是您为表格设置的主键。