简体   繁体   中英

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

            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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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