title: Select Query to Update
body: <p>I have a select query like that </p>
  
  <pre><code>select er.*,
         (@rank := if(@ep = exam_place_id, @rank + 1,
                      if(@ep := exam_place_id, 1, 1) 
                     )
         ) as ranking
  from examresults er cross join
       (select @rank := 0, @ep := -1) params
  order by exam_place_id,
           point desc;
  </code></pre>
  
  <p>I would like to update my <strong>class_ranking</strong> column with the values I get as <strong>ranking</strong> so I try to turn my select query to update like </p>
  
  <pre><code>      update examresults inner join
  (select er.*,
         (@rank := if(@ep = exam_place_id, @rank + 1,
                      if(@ep := exam_place_id, 1, 1) 
                     )
         ) as ranking
  from examresults er cross join
       (select @rank := 0, @ep := -1) params
  order by exam_place_id,
           point desc
  ) t3 
  ON examresults.O_NO = t3.O_NO
  set examresults.class_ranking = t3.ranking
  </code></pre>
  
  <p>however I recieve wrong ranks on class_ranking which works correct with select query. </p>
  
  <p><a href="https://i.stack.imgur.com/iFk2i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iFk2i.png" alt="enter image description here"></a></p>
  
  <p>thanks</p>