Re: SQL query prob

"Tony Andrews" <[email protected]> Wed, 19 Mar 2003 13:19:16
Newsgroups gmane.comp.db.oracle.devel
Message-ID <LYRIS-1796914-918606-2003.03.19-13.01.06--gcdod-oracle#[email protected]>
Sounds like you are looking for any kind of overlap?

If you have 2 date ranges (S1,E1) and (S2,E2) then they overlap only:
WHERE ( E1 >= S2 AND E2 >= S1 )

To see why, look at the 2 possibilities for non-overlap:

1) Range 1 ends before Range 2 starts (E1 < S2)

S1-------E1
              S2------E2

2) Range 2 ends before Range 1 starts (E2 < S1)

             S1------E1
S2-------E2

So non-overlap is defined as:

WHERE ( E1 < S2 OR E2 < S1 )

And therefore overlap is defined as:

WHERE NOT ( E1 < S2 OR E2 < S1 )

which is logically equivalent to:

WHERE ( E1 >= S2 AND E2 >= S1 )

---
Change your mail options at http://p2p.wrox.com/manager.asp or 
to unsubscribe send a blank email to [email protected].