title: Using a joinquery's results in a union query to calculate a new value
body: <p>I am trying to merge two queries so that I can see the results of the two queries on one line. </p>
  
  <p>The first query is</p>
  
  <blockquote>
    <p>SELECT userscore.week, userlist.user_id, userteam.user_teams, userscore.team_points, userplayers.team_players FROM wp_table1 as userlist join wp_table2 as userteam on userlist.user_id = userteam.user_id join wp_table3 as userscore on userteam.user_teams = userscore.user_teams join wp_table4 as userplayers on userteam.user_teams = userplayers.user_teams AND userscore.week = userplayers.week WHERE userlist.list_id = 2 AND userlist.unsub_date = 0 and userscore.week = 22 and userplayers.week = 22</p>
  </blockquote>
  
  <p>and by way of example, for one row returns </p>
  
  <ul>
  <li>week = 22</li>
  <li>user_id = 5</li>
  <li>user_teams = 8087 </li>
  <li>team_points = 160.81 </li>
  <li>team_players = 13,163,238,482,42,212,398,471,222,442,353</li>
  </ul>
  
  <p>I have a second query </p>
  
  <blockquote>
    <p>select round(sum(ppp),2) as gwpoints from ( SELECT sum(points) as ppp FROM wp_table5 WHERE season_id = 77 AND (week between 22 AND 26) and player_id IN (13,163,238,482,42,212,398,471,222,442,353) group by week union SELECT points as ppp FROM wp_table5 WHERE season_id = 77 AND (week Between 22 AND 25) and player_id IN (13,163,238,482,42,212,398,471,222,442,353) group by week ORDER BY ppp DESC ) as dervpointstable</p>
  </blockquote>
  
  <p>which returns gwpoints = 194.32</p>
  
  <p>You can see the above query contains the results of the first query, userplayers.team_players = 13,163,238,482,42,212,398,471,222,442,353</p>
  
  <p>I would like to merge these queries so I get back </p>
  
  <ul>
  <li>week = 22</li>
  <li>user_id = 5</li>
  <li>user_teams = 8087</li>
  <li>team_points = 160.81</li>
  <li>team_players = 13,163,238,482,42,212,398,471,222,442,353</li>
  <li>gwpoints = 194.32</li>
  </ul>
  
  <p>but each time I try I get MySQL errors. Can anyone help please?</p>