missyevil Posted March 30, 2006 Share Posted March 30, 2006 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_loginFROM jobseekers, jsloginWHERE 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. Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/ Share on other sites More sharing options...
wickning1 Posted March 30, 2006 Share Posted March 30, 2006 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_loginFROM jobseekers s INNER JOIN jslogin j ON s.userid=j.useridWHERE 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. Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/#findComment-22448 Share on other sites More sharing options...
missyevil Posted March 30, 2006 Author Share Posted March 30, 2006 TIMESTAMP... Should it be a simple DATETIME? Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/#findComment-22461 Share on other sites More sharing options...
fenway Posted March 31, 2006 Share Posted March 31, 2006 Don't get me started -- everything should be a DATETIME. TIMESTAMP columns have never been properly implemented, even in 5.0. Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/#findComment-22536 Share on other sites More sharing options...
wickning1 Posted March 31, 2006 Share Posted March 31, 2006 That won't break the query though. Something else is wrong. Maybe you have a PHP problem. Try running this query through phpMyAdmin or something similar. Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/#findComment-22614 Share on other sites More sharing options...
fenway Posted March 31, 2006 Share Posted March 31, 2006 Of course -- I figured that the poster used your solution irrespective of column type. Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/#findComment-22731 Share on other sites More sharing options...
missyevil Posted April 1, 2006 Author Share Posted April 1, 2006 OK, I changed the js_last_login column type to DATETIME (thanks for the tip - didn't realise there was a problem with TIMESTAMP), and now it is working!!Thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/6209-finding-records-with-timestamp-more-than-a-given-time-ago/#findComment-22867 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.