这是优化 MySQL 查询的正确方法吗?
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据此文档,您的 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.