title: Php Mysql sum over 2 colums and select from 2 tables
body: <p>I have a MySQL database with 3 tables.</p>
  
  <ul>
  <li>Table player</li>
  </ul>
  
  <pre><code>
  P_id = content (1, 2, 3,)
  
  P_name = content (Spieler1name, Spieler2name, Spieler3name)
  </code></pre>
  
  <ul>
  <li>Table tournament</li>
  </ul>
  
  <pre><code>
  T_id = content (1, 2)
  
  T_date = content (2018, 2019)
  
  T_players = content (123, 123)
  </code></pre>
  
  <ul>
  <li>Table Games</li>
  </ul>
  
  <pre><code>
  G_id = content (1, 2)
  
  G_tournament_id = content (T_id from table tournament)
  
  G_player_away = Content (as an example user id 1)
  
  G_player_home = content (as an example user id 2)
  
  G_player_away_points = Content (11)
  
  G_player_home_points = Content (8)
  </code></pre>
  
  <p>The Games table has even more data.</p>
  
  <p>Now I want to create a table with PhP as ranking.</p>
  
  <p>Place   name   points</p>
  
  <ol>
  <li><p>Spieler1name   11</p></li>
  <li><p>Spieler2name  8</p></li>
  <li><p>Spieler3name  4</p></li>
  <li><p>....</p></li>
  </ol>
  
  <p>Can someone tell me how the php query from the mysql database works? I tested this but it doesn't work.</p>
  
  <pre><code>SELECT SUM(G_player_away_points) AS total FROM Games 
  UNION
  SELECT SUM(G_player_home_points) AS total FROM Games
  GROUP BY G_player_away</code></pre>
  
  <p>In the code above, he also sums the points from the opponent. This is of course not correct, it should only the points obtained by him appear in the output with php table. Furthermore you have to get the name from the table players. Can someone help me?</p>