[英]update table1 by getting values from two tables
I am using mysql database Want to update table1 on specific condition by fetching values from two or more tables example 我正在使用mysql数据库要通过从两个或多个表示例中获取值来在特定条件下更新table1
table1
id | stdId | trId | std_name | std_lname |std_edu_college |std_edu_cource
01 | 1256 | 2341 |
student table
stdId | name | lname
1256 |Mallu |Malage
student_education table
stdId | college | cource
1256 | BEC | Engineering
Want to update table1 with student and student_education data 想要使用学生和学生的教育数据更新表1
Like this i have around 100 columns in table1 with different column name I know using update table1 by joining and set each respected column but i want to update like looping or easy way So someone please help me 像这样,我在table1中大约有100列具有不同的列名,我知道通过加入并设置每个受尊重的列来使用update table1,但是我想像循环或简便方法那样进行更新,所以有人请帮助我
Try this one 试试这个
UPDATE `table1` as tbl
inner join student as std on tbl.stdId=std.stdId
inner join student_education as stdEd on tbl.stdId=stdEd.stdId
SET tbl.`std_name`=std.name
SET tbl.`std_lname`=std.lname
SET tbl.`std_edu_college`=stdEd.college
SET tbl.`std_edu_cource`=stdEd.cource
WHERE tbl.stdId=1256
I thing it will help you to solve your issue. 我认为这将帮助您解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.