title: SQL Server Join on Select statement using count() and group by
body: <p>I have two tables in SQL Server, <code>tbl_disputes</code> and <code>tbl_disputetypes</code>. The <code>tbl_disputes</code> table contains a foreign key column <code>disputetype</code>. The table <code>tbl_disputetypes</code> contains the primary key field <code>disputetypeid</code> and <code>disputetypedesc</code>. The following query gives me a count of each <code>disputetype</code> from the <code>tbl_disputes</code> table. </p>
  
  <pre><code>select disputetype, count(disputetype) as numberof
  from tbl_disputes
  group by disputetype
  </code></pre>
  
  <p>What sort of join or subquery do I need to use to display the 
  <code>tbl_disputetypes.dbo.disputetypedesc</code> instead of <code>tbl_disputes.dbo.disputetype?</code></p>
  
  <p><strong>EDIT</strong> Issue was because disputetypedesc was set as TEXT. I changed it to nvarchar, and the following query worked:</p>
  
  <pre><code>SELECT
      tbl_disputetypes.disputetypedesc,
      count(tbl_disputetypes.disputetypedesc)
  FROM
      tbl_disputes Left OUTER JOIN
      tbl_disputetypes ON tbl_disputes.disputetype = tbl_disputetypes.disputetypeid
  group by tbl_disputetypes.disputetypedesc
  </code></pre>