title: Most efficient way to select record if a value has changed
body: <p>What would be the most efficient way to select a record when one of the value has changed? 
  Ex: </p>
  
  <p>I have an account history table like below where records are being created when the account change:</p>
  
  <pre><code>Id  AcctNb Active Created
  8   123456 1      01/03/2012
  6   123456 0      01/01/2012
  </code></pre>
  
  <p>I like to find an efficient way to return the record where the active status has changed since the last entry.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The query I am using at the moment which works but inefficiently"</p>
  
  <pre><code>select d1.acctNb,d1.active, d2.active 
  from d044 d1 , d044 d2 
  where d1.created = '2012-04-14'
  and d1.acctNb = d2.acctNb 
  and d2.created = (select max(d.created) from d044 d where d.acctNb = d2.acctNb and d.id != d1.id)   
  and (d1.active != d2.active)
  </code></pre>