MySQL从其他表取字段数据更新到本表

2019-02-16 09:13:36   MySQL
  MySQL  

MySQL从别的表取字段数据更新到本表

eg.从table2中取slug字段更新到table1中的slug字段(按照name相同)

  • SQL1
    update table1 T1 join table2 T2 on T1.name = T2.name set T1.slug = T2.slug;
  • SQL2
    update table1 T1 set T1.slug = (select T2.slug from table2 T2 where T1.name = T2.name);
  • SQL3
    update table1 T1 set T1.slug = T2.slug from T1 join table2 T2 on T1.name = T2.name;
vien.tech版权所有,允许转载,但转载请注明出处和原文链接: https://vien.tech/article/62
欢迎小伙伴们在下方评论区留言 ~ O(∩_∩)O
文章对我有帮助, 点此请博主吃包辣条 ~ O(∩_∩)O

猜你喜欢


评论

There are no comments yet.
未登录

登录后即可发表评论

登录或注册