What is a simple and efficient way to find rows with time-interval overlaps in SQL? -


i have 2 tables, both start time , end time fields. need find, each row in first table, of rows in second table time intervals intersect.

for example:

           <-----row 1 interval-------> <---find this--> <--and this--> <--and this--> 

please phrase answer in form of sql where-clause, , consider case end time in second table may null.

target platform sql server 2005, solutions other platforms may of interest also.

select *  table1,table2  table2.start <= table1.end  , (table2.end null or table2.end >= table1.start) 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -