Muhammad Irfan
Muhammad Irfan

Reputation: 1457

is this the correct way to optimize MySQL Query?

  $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..

Upvotes: 4

Views: 214

Answers (1)

Bernard
Bernard

Reputation: 7961

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.

Upvotes: 2

Related Questions