comparing results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
t2birkey
Forum Commoner
Posts: 28
Joined: Mon Feb 09, 2009 8:41 pm

comparing results

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: comparing results

Post 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.
t2birkey
Forum Commoner
Posts: 28
Joined: Mon Feb 09, 2009 8:41 pm

Re: comparing results

Post by t2birkey »

Yeh, I know that is possible. Id rather not use that method, although if its the only possible way.. :)
Post Reply