title: Detect overlapping ranges and correct then in oracle
body: <p>Googling it a bit I found this to be an interesting question. Would like you guys shots.</p>
  
  <p>Having my table</p>
  
  <pre><code>USER    |   MAP |   STARTDAY    |   ENDDAY
  1       |   A   |   20110101    |   20110105
  1       |   B   |   20110106    |   20110110
  2       |   A   |   20110101    |   20110107
  2       |   B   |   20110105    |   20110110
  </code></pre>
  
  <p>Whant I want is to fix user's <code>2</code> case, where maps <code>A</code> and <code>B</code> overlaps by a couple days (from 20110105 until 20110107).
  I wish I was able to query that table in a way that it never return overlapping ranges. My input data is falky already, so I don't have to worry with the conflict treatment, I just want to be able to get a single value for any given <code>BETWEEN</code> these dates.</p>
  
  <p>Possible outputs for the query I'm trying to build would be like</p>
  
  <pre><code>USER    |   MAP |   STARTDAY    |   ENDDAY
  2       |   B   |   20110108    |   20110110 -- pushed overlapping days ahead..
  2       |   A   |   20110101    |   20110104 -- shrunk overlapping range
  </code></pre>
  
  <p>It doesn't even matter if the algorithm causes "invalid ranges", e.g. Start = <code>20110105</code>, End = <code>20110103</code>, I'll just put null when I get to these cases.</p>
  
  <p>What would you guys say? Any straight forward way to get this done?</p>
  
  <p>Thanks!</p>
  
  <p>f.</p>