Given two tables (t1 and t2) with fields "start" and "end", what is the most 
efficient method of finding the all the intervals in the first table that 
overlap any interval in the second table?

Right now, I use a query like:

SELECT t1.name, t2.name FROM t1, t2
WHERE t1.start <= t2.end AND t1.end >= t2.start;

I use a key (start, end) in each table.

Is there anything else that I can do to optimize this type of query (i.e. 
add keys, change the select statement)?  The tables typically have thousands 
of records, so optimizing this query is very important.

Thanks in advance for any help you can give me,

Colin

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to