[sqlite] Is there a way to inner join on named intervals?

2010-08-13 Thread Peng Yu
Hi, Suppose that I have a table A, each row represents a interval. For example, the first row represents an interval [1,10) with a name a. The first and second rows are considered overlapping because the interval [1,10) and interval [5,15) intersect and both rows have the same name a. name left

Re: [sqlite] Is there a way to inner join on named intervals?

2010-08-13 Thread Jim Morris
Did you try something like(pseudo code): select * from A inner join B on A.name = B.name AND ( B.left between(A.left,A.right) OR B.right between(A.left,A.right) ) On 8/13/2010 8:07 AM, Peng Yu wrote: Hi, Suppose that I have a table A, each row represents a interval. For example, the first

Re: [sqlite] Is there a way to inner join on named intervals?

2010-08-13 Thread Simon Davies
On 13 August 2010 16:07, Peng Yu pengyu...@gmail.com wrote: Hi, Suppose that I have a table A, each row represents a interval. For example, the first row represents an interval [1,10) with a name a. The first and second rows are considered overlapping because the interval [1,10) and interval

Re: [sqlite] Is there a way to inner join on named intervals?

2010-08-13 Thread Pavel Ivanov
I don't understand where do you see a problem but it looks like this join will do what you want: select * from A, B where A.name = B.name and A.left B.right and A.right B.left I could use an external program (such as python sqlite package) to enumerate all the named interval from table A and

Re: [sqlite] Is there a way to inner join on named intervals?

2010-08-13 Thread Peng Yu
On Fri, Aug 13, 2010 at 11:32 AM, Pavel Ivanov paiva...@gmail.com wrote: I don't understand where do you see a problem but it looks like this join will do what you want: select * from A, B where A.name = B.name and A.left B.right and A.right B.left I could use an external program (such

Re: [sqlite] Is there a way to inner join on named intervals?

2010-08-13 Thread Pavel Ivanov
My next question is what index I should create on table A and B to speed up such an inner join? Are indexes on each of the first three column of each table enough? What is the best comparison (along with the appropriate indexes) in term of the performance? Indexes on each field never help.