title: SQL detect change in row
body: <p>I have data from sql server attached :</p>
  
  <pre><code>select * from log
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4R2JM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4R2JM.png" alt="data"></a></p>
  
  <p>What I want to do is I want to check if there any changes in code for the column name. So if you see the data from table log, the code change 2 times (B02,B03).</p>
  
  <p>What I want to do is I want to retrieve the row which is the first changes everytime the code change. In this sample, the first changes is on the red box. So I want to have the result for row 5 and row 9.</p>
  
  <p>I've tried to use partition like code below:</p>
  
  <pre><code>select a.name,a.code from(
  select name,code,row_number() over(partition by code order by name) as rank from log)a
  where a.rank=1
  </code></pre>
  
  <p>and get result like this. </p>
  
  <p><a href="https://i.stack.imgur.com/ofwkV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ofwkV.png" alt="result"></a></p>
  
  <p>However, I don't want the first row to be retrieved. Since it is the first value and I don't need that. So i just want to retrieve the changes indicates by column code. Please help if you know how to do it.</p>
  
  <p>and please note, I can't write query using filter <code>where code &lt;&gt; 'B01'</code>, because in this case, I don't know what is the first value. </p>
  
  <p>Please assume the first value is the data that first inserted into the table.</p>