title: How to show the difference between two counts using aliases?
body: <p>I'm creating custom views that show totals for different things in a database, and I'd like to also show the differences.</p>
  
  <p>For example;</p>
  
  <pre><code>SELECT
     (SELECT COUNT(*) FROM `documents`) AS `doc_count`,
     (SELECT COUNT(*) FROM `contacts`) AS `user_count`,
     (`doc_count` - `user_count`) AS `difference`;
  </code></pre>
  
  <p>I get an error using the aliases this way. Is there a way write this query without repeating <code>select count(*)</code> queries.</p>