title: SQL Server : count pairs from two different columns
body: <p>I have a query I need for an application I'm building, but I'm struggling to find the best answer.</p>
  
  <p>Suppose I have a table named <code>Messages</code>, with the following columns:</p>
  
  <pre><code>MessageID, From, To, Text
  </code></pre>
  
  <p>I want to count all messages between <code>From</code> and <code>To</code> such as that if the table looks like this:</p>
  
  <pre><code>ID From  To   Text
  ------------------
   1    a   b     hi
   2    b   a  hello
   3    a   c   test
  </code></pre>
  
  <p>So basically I want the result to look like </p>
  
  <pre><code>a, b, 2
  a, c, 1
  </code></pre>
  
  <p>Appreciate your help</p>