title: select count(*) as part of larger select query
body: <p>I'm using two queries:</p>
  
  <pre><code>select * from ControlPoints where LineGroup = 123001
  select count(*) from BitAssignments where LineGroup = 123001
  </code></pre>
  
  <p>to determine if I need to update the BitAssignments table. Can I combine these two queries somehow? </p>
  
  <p>These two tables are populated from an external source, and the idea is 1) to see if any members of ControlPoints are missing, and 2) if they are present, to see if all the BitAssignments are in the table. </p>
  
  <p>Schema are as follows:</p>
  
  <pre><code>ControlPoints table
     LineGroup     int (primary key)
     Name          string
     NumControls   int
     NumInd        int
  
  BitAssignments table
     LineGroup     int
     BitPosition   int
     Mnemonic      string
  </code></pre>
  
  <p>For a given ControlPoint, there will be only one record in the ControlPoints table, but there may be hundreds of rows of Bit data in the BitAssignments table. </p>
  
  <p>I need a query that tells me if new control points in the external data have been added (or deleted), or if new bit assignments to an existing control point have been added/removed from external data. The alternative is rebuilding both tables from scratch, but this process takes over 12 hours to complete (about 300,000 records in BitAssignments).</p>
  
  <p>Something along the lines of:</p>
  
  <pre><code>select a.LineGroup b.select count(Mnemonic) from ControlPoints a, BitAssignments b where a.LineGroup=123001 
  </code></pre>
  
  <p>which, of course, does not work.</p>