title: How to find these master records whose totals are not accurate
body: <p>I have two tables (master-details relationship). The master table has a column (called total) recording the number of details records for the same master record. Having this column is for the performance reason). Here are the table specs:</p>
  
  <pre><code>table: MySum
  column: id
  column: total (total of MyDetail records for the same MySum record)
  
  table: MyDetail
  column: name
  column: MySum
  </code></pre>
  
  <p>Because deletion of details records, the total in the master table may not be correct and so I would like to find these master records whose totals are not accurate. Here is the SQL I have. However, it generates zero records and I know this is not right based on the actual data.</p>
  
  <pre><code>select s.id, s.total from MySum s where s.total &lt;&gt; (select count(*) from MyDetail d where s.id = d.MySum group by d.MySum)
  </code></pre>
  
  <p>What is the right SQL statement? </p>
  
  <p>I am using MS SQL Server and database-specific statement is okay for me. However, generic statement would be better.</p>