title: Find records with more than 1 column value in SQL
body: <p>To simplify things here is my table structure:</p>
  
  <p><strong>Table Name: OCRD</strong></p>
  
  <pre><code>CardCode       E_Mail          U_NoEmail
  123            test@hi.com     Y
  124            test@hi.com     N
  125            other@hi.com    Y
  126            mail@hi.com     N
  </code></pre>
  
  <p>The table contains a unique ID, an email address, and a third column (<code>U_NoEmail</code>) which shows a preference for the email to be <code>opted in</code> or not to emails. It is a bit counterintuitive and Y = Opted Out, <code>N = Opted In</code>.  The <code>U_NoEmail</code> column can also be <code>NULL</code>.</p>
  
  <p>I am trying to use a single query against this table to return a count.  The count is the number of email addresses that have more than one value for <code>U_NoEmail</code> in the table. In other words, I'd like to find the total number of email addresses that are opted in AND out, which from a business perspective is not helpful.</p>
  
  <p>I can't figure out how to do this.  For example, I can get this by email address with the following query:</p>
  
  <pre><code>SELECT E_Mail, COUNT(DISTINCT E_Mail) 
  FROM OCRD
  GROUP BY E_Mail
  HAVING COUNT(DISTINCT U_NoEMail) &gt; 1
  </code></pre>
  
  <p>Which returns all the addresses with more than one value for <code>U_NoEmail</code>.  But I can't figure out how to get this as a single total.  If I try the following:</p>
  
  <pre><code>SELECT COUNT(*) FROM
  (
  SELECT E_Mail, COUNT(DISTINCT E_Mail) 
  FROM OCRD
  GROUP BY E_Mail
  HAVING COUNT(DISTINCT U_NoEMail) &gt; 1
  ) result
  </code></pre>
  
  <p>I get the error:
  No column was specified for column 2 of 'result'.</p>