I am trying to do what it seems to be a simple SQL operation, but I just cannot find the correct syntax to do this quickly. I am using SQLite.
The main problem is that I have a table whose primary key is (objUid, time). It contains the objUid, time and frame columns. For the purposes of this question, a frame is an opaque value.
I would like to extract for each objUid: objUid, minTime, frame value in minTime, maxTime, frame value in maxTime.
... and I would like to do it as quickly as possible.
I have it right now and it works, but if I select the โNATURAL JOINโ instructions (which means that I don't get the โframeโ column), it's about twice as fast.
SELECT * FROM (
SELECT * FROM (
SELECT objUid, min(time) as minTime, max(time) as maxTime FROM motion GROUP BY objUid
) NATURAL JOIN (
SELECT objUid, time as minTime, frame as minFrame FROM motion
)
) NATURAL JOIN (SELECT objUid, time as maxTime, frame as maxFrame FROM motion)
Any ideas?
Thank!