title: MySQL - Find pairs in either column
body: <p>I have a VERY large table called <code>fullNames</code>:</p>
  
  <pre><code>+----+-----------+----------+--------+
  | id | name1     | name2    | count  |
  +----+-----------+----------+--------+
  | 1  | Homer     | Simpson  |   2    | &lt;-- Homer clicked Simpson's name 2 times
  | 2  | Bart      | Simpson  |   1    | &lt;-- Bart clicked Simpson's name once
  | 3  | Simpson   | Bart     |   4    | &lt;-- Simpson clicked Bart's name 4 times
  ......................................
  ......................................
  | 80 | Steven    | Baldwin  |   7    | &lt;-- Steven clicked Baldwin's name 7 times
  | 81 | Alec      | Baldwin  |   6    | &lt;-- Alec clicked Balwin 6 times, but there's NO relationship w/ Steven's clicks
  +-------+--------+----------+--------+
  </code></pre>
  
  <p>Essentially I need to be able to determine how many times the given user (<code>name1</code>) has clicked on a given name (<code>name2</code>), then determine the opposite - how many times <code>name2</code> has clicked on <code>name1</code>. When Simpson loads up his page, he should see a list of names put in order based on the combined <code>count</code>s of matching pairs that include his name. That list would look like this:</p>
  
  <pre><code>Bart       5
  Homer      2
  </code></pre>
  
  <p>When there's a click, I can insert it into the table no problem, BUT I don't know how to query for something like this... I guess it would ultimately need to come out as a JSON object/array so this can be made into a native mobile app, so bonus points if you feel like working that out too!</p>