I have a sqlite database with 2 tables. Table a
has a running list of events and the times they happened. Table b
has the start and finish of time each event.
How can I find the minimum event from table a
for each group defined in table b
? Schema is described in my SQLFiddle.
I'm trying to get a result like:
id1 id2 time event
c1 d1 2 5
c1 d2 1.2 10
c1 d1 5 8.2
Best Answer
Cfr. http://sqlfiddle.com/#!5/284fb/4
Another way to obtain these results:
With your current schema, that contains a serious flaw, there is no way to obtain your result in a timely fashion. With some simple modifications, you can get it in 21 seconds.
Modify your tables as follows:
I've given b a primary key. a.idA contains a reference (foreign key) to b. This update took quite some time. Now the following query finishes in 21 seconds.