title: MySQL: Sum of multiple subqueries
body: <p>I need to order a <code>MySQL</code> query by the resulting SUM of multiple subqueries. </p>
  
  <p>Here's some example code for what I'm trying to do:</p>
  
  <pre><code>SELECT  ...
          (SELECT SUM(
             (SELECT one_result ... LIMIT 1) as plays1,
             (SELECT one_result ... LIMIT 1) as plays2,
             (SELECT one_result ... LIMIT 1) as plays3
          )) as total_plays
  FROM plays
  ORDER BY total_plays
  </code></pre>
  
  <p>Basically, I need to run three subqueries that'll each return an integer. </p>
  
  <p>I need to order the entire query by the <code>SUM()</code> of these integers.</p>
  
  <p>When I try to run this query I get a syntax error.</p>
  
  <p>Could someone let me know what the proper syntax is for summing multiple subqueries?</p>
  
  <p>I've also already tried:</p>
  
  <pre><code>SELECT  ...
          (SELECT one_result ... LIMIT 1) as plays1,
          (SELECT one_result ... LIMIT 1) as plays2,
          (SELECT one_result ... LIMIT 1) as plays3
          SUM(plays1, plays3, plays3) as total_plays
  FROM plays
  ORDER BY total_plays
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>@JoeC and @SATSON provided similar answers that solved this. Here's my (working) real query in case this helps anyone else get started on their own query:</p>
  
  <p>````</p>
  
  <pre><code>SELECT  song.title as title,
          song.file_name as unique_name,
          song.artist as artist,
         (SELECT difficulty FROM chart WHERE id = song.easy_chart ORDER BY scoring_version ASC LIMIT 1) as easy_difficulty,
         (SELECT difficulty FROM chart WHERE id = song.hard_chart ORDER BY scoring_version ASC LIMIT 1) as hard_difficulty,
         (SELECT difficulty FROM chart WHERE id = song.master_chart ORDER BY scoring_version ASC LIMIT 1) as master_difficulty,
         (plays.easy_plays + plays.hard_plays + plays.master_plays) as total_plays
  FROM song
  INNER JOIN (SELECT parent_song_id,
                 (SELECT global_plays ORDER BY scoring_version ASC LIMIT 1) as easy_plays,
                 (SELECT global_plays ORDER BY scoring_version ASC LIMIT 1) as hard_plays,
                 (SELECT global_plays ORDER BY scoring_version ASC LIMIT 1) as master_plays
         FROM chart) as plays
  ON plays.parent_song_id = song.id
  ORDER BY total_plays DESC
  LIMIT 9
  OFFSET 0
  </code></pre>
  
  <p>````</p>