title: mysql count of distinct records after match
body: <p>Given table 'x':</p>
  
  <pre><code>Source  Dest    Type
  A       B       2
  A       D       2
  B       C       2
  </code></pre>
  
  <p>Now I want the total count of Source and destination removing the matching ones..</p>
  
  <p>Example of above one: For type 2, Count will be 4, i.e. Count(A,B,C,D)</p>
  
  <p>I tried this:</p>
  
  <pre><code>select Count(distinct Source), Count(distinct destination),Count(distinct source)+Count( distinct destination),Type
  from X
  where Type=2 and Src NOT IN (select destination
      from  X
      where Type=2)
  </code></pre>
  
  <p>I need to simplify this query for all the types.</p>
  
  <p>Let me know if there is any way I could do it.</p>
  
  <p>Thanks!</p>