Click to See Complete Forum and Search --> : SQL select problem


fimaro
09-10-2008, 04:00 AM
I've been scratching my head over this problem. Tried searching for a similar problem, but I can't seem to find one. So here it is:

I have a table with 3 columns (timestamp, data1, data2)

I want to select timestamp, data1 and data2 where timestamp is between 'now' and 'then', but where data2 is the result of timestamp between 'now + 1 seconds' and 'then + 1 seconds'.

In other words, data1 is from 13:00 - 13:01, but data2 is from 13:01 - 13:02 if that makes any sence.

I thought it would be a simple query, but I just can't figure out how to do it ;-\

Any help or pointers as to how to solve this?

Phill Pafford
09-10-2008, 02:59 PM
Haven't test this but try something like this, maybe explain a little more if you need more help.


SELECT timestamp, data1, data2
FROM table
WHERE data2
BETWEEN '2008-09-01 00:00:00' /* THIS IS NOW */
AND '2008-09-02 00:00:00' /* THIS IS THEN */
AND data2
BETWEEN '2008-09-01 00:00:00' + INTERVAL 1 SECOND /* THIS IS NOW */
AND '2008-09-02 00:00:00' + INTERVAL 1 SECOND /* THIS IS THEN */