title: How to count two separate columns in the same table and sum them into a new column
body: <p>I have two tables: <strong>playernames</strong> and <strong>matches</strong>.</p>
  
  <pre><code>SELECT * FROM playernames;
   id |       name       
  ----+------------------
   38 | Abe Lincoln
   39 | Richard Nixon
   40 | Ronald Reagan
  (3 rows)
  
  SELECT * FROM matches;
   match_id | winner | loser 
  ----------+--------+-------
          6 |     38 |    39
          8 |     38 |    39
          9 |     39 |    38
         10 |     38 |    39
         11 |     40 |    39
  (5 rows)
  </code></pre>
  
  <p>I need to create a single query that returns four columns: <strong>id, name, wins, matches</strong>. But even with joins and subqueries, I can't seem to get all of it in one query. The closest I have come is to execute two separate queries. This is the query to calculate the total wins per player:</p>
  
  <pre><code>SELECT playernames.id, name, COUNT(*) AS wins 
  FROM matches, playernames 
  WHERE winner = playernames.id 
  GROUP BY playernames.id, winner;
   id |       name       | wins 
  ----+------------------+------
   38 | Abe Lincoln      |    3
   39 | Richard Nixon    |    1
   40 | Ronald Reagan    |    1
  (3 rows)
  </code></pre>
  
  <p>But I have to issue a separate query if I want to correctly calculate the total number of matches for each player:</p>
  
  <pre><code>SELECT playernames.id, name, COUNT(*) 
  FROM matches, playernames 
  WHERE playernames.id = winner 
  OR playernames.id = loser 
  GROUP BY playernames.id;
   id |       name       | count 
  ----+------------------+-------
   40 | Ronald Reagan    |     1
   38 | Abe Lincoln      |     4
   39 | Richard Nixon    |     5
  (3 rows)
  </code></pre>
  
  <p>I'm avoiding cluttering up this question with the many incorrect attempts I've made at combining these into a single query. Can anyone advise me on how to properly combine these two queries into one?</p>