Mysql update多表联合更新

下面我建两个表,并执行一系列sql语句,仔细观察sql执行后表中数据的变化,很容易就能理解多表联合更新的用法

student表                                                                         class表

Mysql update多表联合更新_第1张图片     Mysql update多表联合更新_第2张图片

1. 执行 UPDATE student s , class c SET s.class_name='test00',c.stu_name='test00' WHERE s.class_id = c.id

student表                                                                class表

Mysql update多表联合更新_第3张图片    Mysql update多表联合更新_第4张图片

2. 执行 UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name='test11',c.stu_name='test11'

student表                                                                  class表

Mysql update多表联合更新_第5张图片    Mysql update多表联合更新_第6张图片

3. 执行 UPDATE student s LEFT JOIN class c ON s.class_id = c.id SET s.class_name='test22',c.stu_name='test22'

student表                                                                      class表

Mysql update多表联合更新_第7张图片    Mysql update多表联合更新_第8张图片

4. 执行 UPDATE student s RIGHT JOIN class c ON s.class_id = c.id SET s.class_name='test33',c.stu_name='test33'

student表                                                                class表

Mysql update多表联合更新_第9张图片    Mysql update多表联合更新_第10张图片

5. 执行 UPDATE student s JOIN class c ON s.class_id = c.id SET s.class_name=c.name , c.stu_name=s.name

student表                                                                class表

Mysql update多表联合更新_第11张图片    Mysql update多表联合更新_第12张图片

你可能感兴趣的:(Mysql)