title: Union returns two rows if data is different, one if it's the same! Why?
body: <p>Taking the following statement:</p>
  
  <pre><code>select count( 1 ) as cnt from tbl where val= 1 
  union
  select count( 1 ) as cnt from tbl where val = 0
  </code></pre>
  
  <p>If the two selects return the same value the result is a single row with that value. If the selects return different values the result is two rows with the two values. Why?</p>
  
  <p>I am trying to find the total count of rows using:</p>
  
  <pre><code>select sum (cnt) from
  (
      select count( 1 ) as cnt from tbl where value = 1
      union
      select count( 1 ) as cnt from tbl where value = 0
  ) as tbl2
  </code></pre>
  
  <p>which works as expected if the counts are different but gives half the value if the counts are the same... </p>
  
  <p>(PS : More interested in why sql behaves this way than in a solution)</p>