簡體   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