这是优化 MySQL 查询的正确方法吗?

发布于 2024-09-26 08:19:19 字数 408 浏览 0 评论 0原文

  $sql="update users_contain 
  set
  wood_max      =   (Select building_production from building_level where merge_id=$subPrimaryKey and empire_id=$user_empireID) ,
  iron_max      =   wood_max,
  clay_max      =   wood_max
  where user_id =   $user_id";

现在有一个问题。

wood_max 将始终先于iron_max 和clay_max 更新。所以使用这种方式是安全的? 当我知道它对于所有三个字段具有相同的值时,我不想使用内部查询来更新iron_max和clay_max。

  $sql="update users_contain 
  set
  wood_max      =   (Select building_production from building_level where merge_id=$subPrimaryKey and empire_id=$user_empireID) ,
  iron_max      =   wood_max,
  clay_max      =   wood_max
  where user_id =   $user_id";

Now there is a question.

will wood_max will always be updated first than iron_max and clay_max. so it is safe to use this way??
i do not want to use inner query for updating the iron_max and clay_max when i know it has same value for all three fields..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2024-10-03 08:19:19

根据此文档,您的 UPDATE 语句按您希望的方式工作: http://dev.mysql.com/doc/refman/5.1/en/ansi-diff-update.html

测试一下以确定,但我认为你没问题。

According to this documentation, your UPDATE statement works as you want it to: http://dev.mysql.com/doc/refman/5.1/en/ansi-diff-update.html

Test it to be sure, but I think you're fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文