sql - Update table based on number from second table -


i new , programming , wondering if me sql query. have 3 tables. table 1 called student(id,number,teacherid) , table 2nd table called studentupdate (studentid, teacher_number) , third table called teacher (id, number,studentid).

i update table 1 (student table) values table 2 (student update) based on teacherid . how do when table 2 contains teacher number not id ? using sql server 2012. in advance

you can use following query:

update s set teacherid = su.teacher_number student s join teacher t on s.teacherid = t.id  join studentupdate su on s.id = su.studentid 

the above query performs update using 2 join operations:

  • student teacher based on ids of teacher and
  • studentupdate teacher based on id of student.

    so extract table studentupdate info required update (based on limited info given in op).