title: Use Aggregate Function in UNION ALL result set
body: <p>How can I use aggregate Functions in UNION ALL Resultset</p>
  
  <p>FOR EXAMPLE</p>
  
  <pre><code>SELECT A,B FROM MyTable
  UNION ALL
  SELECT B,C FROM MYAnotherTable
  </code></pre>
  
  <p>Result Set Would Be</p>
  
  <pre><code>    A  B
  --------------
      1  2
      3  4
      4  5
      6  7
  </code></pre>
  
  <p>When I tried to get <code>MAX(A)</code> it returns <code>3</code>. I want <code>6</code>.</p>
  
  <p>When I tried to get <code>MAX(B)</code> it returns <code>4</code>. I want <code>7</code>.</p>
  
  <p>Other than <code>Max()</code>, Can I get another aggregate function which user defined?</p>
  
  <p>For example:</p>
  
  <p>(<code>SELECT TOP 1 A WHERE B=5</code>)</p>
  
  <p>Real Case <a href="http://pastie.org/8124275" rel="nofollow">Here</a></p>