Jump to content

Finding records with timestamp more than a given time ago


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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.