繁体   English   中英

通过从两个表获取值来更新table1

[英]update table1 by getting values from two tables

我正在使用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

想要使用学生和学生的教育数据更新表1

像这样,我在table1中大约有100列具有不同的列名,我知道通过加入并设置每个受尊重的列来使用update table1,但是我想像循环或简便方法那样进行更新,所以有人请帮助我

试试这个

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

我认为这将帮助您解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM