Jump to content

Finding records with timestamp more than a given time ago


missyevil

Recommended Posts

Hi,

I've been trying to get a query working that returns a list of users stored in my database, who last logged in over 90 days ago.

I've got this so far:

[code]SELECT jobseekers.forename, jobseekers.surname, jslogin.email, jslogin.js_last_login
FROM jobseekers, jslogin
WHERE jslogin.js_last_login <= SUBDATE(NOW(), INTERVAL 90 DAY);[/code]

But when I run it I get an empty set, when there really should be some entries.

Am still a total newbie, but I hope its clear what I'm trying to do!!

Thank you in advance for any help.
First of all, you are missing a join condition between your two tables. You still have a problem though, because your date subtraction was correct and you shouldn't have gotten an empty set. What data type is the js_last_login column? tinytext, varchar, timestamp, datetime?

[code]SELECT s.forename, s.surname, j.email, j.js_last_login
FROM jobseekers s INNER JOIN jslogin j ON s.userid=j.userid
WHERE j.js_last_login <= NOW() - INTERVAL 90 DAY[/code]
This is how I wrote the query.. you need to replace that "ON s.userid=j.userid" with a true join condition.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.