title: MySql sort query with multiple fields
body: <p>I have two tables "activity_stats" &amp; "activity_stats_values"</p>
  
  <pre><code>activity_stats table
  # id, activity_id, kyf_id, kyf_sort
  618      84          5       1
  619      84          6       2
  638      84          4       3 
  
  activity_stats_values table
  # id, activity_id, player_id, kyf_id, value
  2563    84          46          5       45
  2564    84          46          6       60
  2587    84          47          5       10
  2588    84          47          6       25
  2589    84          49          5       10
  2590    84          49          6       40
  2591    84          48          5       30
  2592    84          48          6       15
  2594    84          46          4       NULL
  2595    84          47          4       80
  2596    84          48          4       NULL
  2597    84          49          4       NULL
  </code></pre>
  
  <p><strong>Requirement</strong>  </p>
  
  <hr>
  
  <p>players should be sorted by values in descending order. Meaning the player with highest value of first keyfigure(kyf_id , kyf_id position based on field "kyf_sort" of table "activity_stats") should be on top (then second key figure, then third key figure).</p>
  
  <p>Expected output</p>
  
  <pre><code># id, activity_id, player_id, kyf_id, value  kyf_sort
   2563   84          46          5       45      1
   2564   84          46          6       60      2
   2594   84          46          4       NULL    3
  
   2591   84          48          5       30      1
   2592   84          48          6       15      2
   2596   84          48          4       NULL    3
  
   2589   84          49          5       10      1
   2590   84          49          6       40      2
   2597   84          49          4       NULL    3
  
   2587   84          47          5       10      1
   2588   84          47          6       25      2
   2595   84          47          4       80      3
  </code></pre>
  
  <p>OR playes ids in order [46,48,49,47]</p>
  
  <pre><code>I tried the following query 
  </code></pre>
  
  <hr>
  
  <pre><code>SELECT    ac_st_v.activity_id,ac_st_v.player_id,ac_st_v.value,ac_st.kyf_id,ac_st.kyf_sort,pl.first_name ,
  (select max(value)  
   from activity_stats_values 
    where activity_id=ac_st_v.activity_id 
       and kyf_id=ac_st.kyf_id 
   group by activity_id) as m_value
  FROM teamplayer.activity_stats_values as ac_st_v
   JOIN teamplayer.activity_stats as ac_st
    ON ac_st_v.activity_id=ac_st.activity_id 
     AND  ac_st_v.kyf_id=ac_st.kyf_id
   JOIN teamplayer.players as pl
    ON ac_st_v.player_id=pl.id
  where ac_st_v.activity_id= 84  
  order by  ac_st_v.player_id,ac_st.kyf_sort,m_value
  </code></pre>
  
  <p>Is there any way to sort the values like this?</p>