title: SQL count occurrences multiple columns
body: <p>From the following table, I would like to count 1) the number of distinct names and 2) the number of occurrences of each name.</p>
  
  <pre><code>+------+------+-------+-------+-------+-------+-------+
  | date | job  |person1|person2|person3|person4|person5|
  +------+------+-------+-------+-------+-------+-------+
  | mon  | clean|  Matt | Bruce | Alan  |Emilce | Linda |
  +------+------+-------+-------+-------+-------+-------+
  | tu   | write| Bruce |  Matt |  Matt | Alan  | Linda |
  +------+------+-------+-------+-------+-------+-------+
  | wen  | mend | Bruce |Emilce |  Matt |  Matt | Linda |
  +------+------+-------+-------+-------+-------+-------+
  | fri  | sew  |  Matt | Linda |Emilce | Alan  | Alan  |
  +------+------+-------+-------+-------+-------+-------+
  </code></pre>
  
  <p>The output should be:<br>
  Names number: 5  </p>
  
  <p>Number of occurrences of each name:</p>
  
  <pre><code>+------+------+
  | Alan |  4   |
  +------+------+
  | Bruce|  3   |
  +------+------+
  |Emilce|  3   |
  +------+------+
  | Linda|  4   |
  +------+------+
  | Matt |  5   |
  +------+------+
  </code></pre>
  
  <p>I've been trying with</p>
  
  <pre><code>SELECT user, count(*) AS count
  FROM (
  SELECT person1 AS user FROM mytable
  UNION ALL
  SELECT person1 FROM mytable
  UNION ALL
  SELECT person3 FROM mytable
  UNION ALL
  SELECT person4 FROM mytable
  UNION ALL
  SELECT person5 FROM mytable
  ) AS all_users
  GROUP BY user
  ORDER BY user
  </code></pre>
  
  <p>But I don´t know how to know the number of names present in the table, and I would like to get the number of occurrences of each name in an array.</p>