Mysql update多表联合更新

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012604745/article/details/80642015

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

student表                                                                         class表

    

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

student表                                                                class表

    

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

student表                                                                  class表

    

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表

    

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表

    

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表

    

展开阅读全文

没有更多推荐了,返回首页