sql >> Base de Datos >  >> RDS >> Oracle

Encuentre registros con rango de fechas superpuestos en SQL

la respuesta anterior no tiene en cuenta las situaciones en las que t2 está completamente dentro de t1

select * from t t1
join t t2 on (t1.datefrom > t2.datefrom and t1.datefrom < t2.dateto  )
          or (t1.dateto   > t2.datefrom and t1.dateto   < t2.dateto  )
          or (t1.dateto   > t2.dateto   and t1.datefrom < t2.datefrom)