Page 1 of 1

comparing results

Posted: Tue Jun 02, 2009 11:55 pm
by t2birkey
I am looking for a way to compare data in a table that stores a timestamp of when an action was accessed by a user. I am wanting to pull from the database ONLY timestamps that are atleast 15 seconds apart from eachother.

Here is a sample select statement without comparin the timestamps.

Code: Select all

SELECT timestamp FROM actions WHERE userid = 1
I am thinking a nested select statement should do something like this.

Re: comparing results

Posted: Wed Jun 03, 2009 1:19 am
by califdon
I can't think of any way to do that with SQL. The way to do it is to use ORDER BY to retrieve the records in datetime order, then use code (PHP or other) to fetch a row, keep track of the datetime stamp, then fetch more rows, discarding any that are within 15 seconds of the previously kept row.

Re: comparing results

Posted: Wed Jun 03, 2009 1:21 am
by t2birkey
Yeh, I know that is possible. Id rather not use that method, although if its the only possible way.. :)