title: Get count of distinct groups in a single SQL query in Firebird 1.5?
body: <p>I ran across the following in a stored procedure:</p>
  
  <pre><code>  for
      select 1
      from   scan_queue
      where  ( date_time_locked is null       )
        and  ( scan_seqno &gt;= :varMinScanSeqno )
        and  ( scan_seqno &lt;= :varMaxScanSeqno )
      group by loan_id, collateral_id, insurance_id
      into   varNotUsed
    do
      varItemsToScan = varItemsToScan + 1;
  </code></pre>
  
  <p>My first thought was that this is probably an inefficient way of counting the number of groups, but my second thought was, "hey, how would you write that in a single query, anyway?"  And I didn't have a good answer.  (So this is more of an academic question.)  I am <em>not</em> looking for a solution that concatenates the IDs, like so:</p>
  
  <pre><code>select count(distinct loan_id || collateral_id || insurance_id)
  from   scan_queue
  where  ( date_time_locked is null       )
    and  ( scan_seqno &gt;= :varMinScanSeqno )
    and  ( scan_seqno &lt;= :varMaxScanSeqno )
  </code></pre>
  
  <p>What is the best way to query this information?</p>
  
  <p><strong>EDIT</strong>: Since I apparently did not make this clear enough, I am using Firebird v1.5.</p>