MySql更新联接表

编程入门 行业动态 更新时间:2024-10-23 07:15:27
本文介绍了MySql更新联接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想更新具有多个联接的语句中的表.虽然我知道联接的顺序并不重要(除非您使用的是优化程序提示),但我还是以某种特定的方式对它们进行了排序,以使其最直观地阅读.但是,这导致我要更新的表不是我开始使用的表,并且在更新它时遇到了麻烦.

I want to update a table in a statement that has several joins. While I know the order of joins doesn't really matter (unless you you are using optimizer hints) I ordered them a certain way to be most intuitive to read. However, this results in the table I want to update not being the one I start with, and I am having trouble updating it.

我想做的一个虚拟例子如下:

A dummy example of what I'd like to do is something like:

UPDATE b FROM tableA a JOIN tableB b ON a.a_id = b.a_id JOIN tableC c ON b.b_id = c.b_id SET b.val = a.val+c.val WHERE a.val > 10 AND c.val > 10;

这里有很多关于使用联接进行更新的文章,但是总是先更新表.我知道这在SQL Server中是可能的,希望在MySQL Too中也可以!

There are many posts about updating with joins here however they always have table being updated first. I know this is possible in SQL Server and hopefully its possible in MySQL Too!

推荐答案

MySQL中的多表UPDATE语法与Microsoft SQL Server不同.您无需说出要更新的表,这在您的SET子句中是隐含的.

The multi-table UPDATE syntax in MySQL is different from Microsoft SQL Server. You don't need to say which table(s) you're updating, that's implicit in your SET clause.

UPDATE tableA a JOIN tableB b ON a.a_id = b.a_id JOIN tableC c ON b.b_id = c.b_id SET b.val = a.val+c.val WHERE a.val > 10 AND c.val > 10;

MySQL的语法中没有FROM子句.

There is no FROM clause in MySQL's syntax.

使用JOIN进行更新不是标准的SQL,MySQL和Microsoft SQL Server都实现了自己的想法,作为对标准语法的扩展.

UPDATE with JOIN is not standard SQL, and both MySQL and Microsoft SQL Server have implemented their own ideas as an extension to standard syntax.

更多推荐

MySql更新联接表

本文发布于:2023-10-24 19:44:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524830.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MySql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!