title: TSQL selecting unique value from multiple ranges in a column
body: <p>A question from a beginner.</p>
  
  <p>I have two tables. One (A) contains <code>Start_time, End_time, Status</code>. Second one (B) contains <code>Timestamp, Error_code</code>. Second table is automatically logged by system every few seconds, so it contains lots of non unique values of Error_code (it changes randomly, but within a time range from table A). What i need is to select unique error code for every time range (in my case every row) from the first table for every time range in table A:</p>
  
  <p>A.Start_time, A.End_time B.Error_code.</p>
  
  <p>I have come to this:</p>
  
  <pre><code>select A.Start_time,
         A.End_time,
         B.Error_code
  from B
    inner join A
      on B.Timestamp between A.Start_time and A.End_time
  </code></pre>
  
  <p>This is wrong, i know.
  Any thoughts are welcome.</p>