title: SELECT COUNT(DISTINCT [name]) from several tables
body: <p>I can perform the following SQL Server selection of distinct (or non-repeating names) from a column in one table like so:</p>
  
  <pre><code>SELECT COUNT(DISTINCT [Name]) FROM [MyTable]
  </code></pre>
  
  <p>But what if I have more than one table (all these tables contain the name field called [Name]) and I need to know the count of non-repeating names in two or more tables.</p>
  
  <p>If I run something like this:</p>
  
  <pre><code>SELECT COUNT(DISTINCT [Name]) FROM [MyTable1], [MyTable2], [MyTable3]
  </code></pre>
  
  <p>I get an error, "Ambiguous column name 'Name'".</p>
  
  <p>PS. All three tables [MyTable1], [MyTable2], [MyTable3] are a product of a previous selection.</p>