title: Getting a distinct value across 2 union sql server tables
body: <p>I'm trying to get all distinct values across 2 tables using a union.</p>
  
  <p>The idea is to get a count of all unique values in the columnA column without repeats so that I can get a summation of all columns that contain a unique columnA.</p>
  
  <p>This is what I tried (sql server express 2008)</p>
  
  <pre><code>select 
      count(Distinct ColumnA) 
  from 
  ( 
      select Distinct ColumnA as ColumnA from tableX where x = y
      union
      select Distinct ColumnA as ColumnA from tableY where y=z
  )
  </code></pre>