2

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

Mahantesh
  • 347
  • 5
  • 20
  • possible duplicate : https://stackoverflow.com/questions/11709043/mysql-update-column-with-value-from-another-table – Esteban Jun 23 '17 at 09:32
  • 4
    Possible duplicate of [mysql update column with value from another table](https://stackoverflow.com/questions/11709043/mysql-update-column-with-value-from-another-table) – Esteban Jun 23 '17 at 09:32

1 Answers1

0

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.

Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51