countdrac Posted December 7, 2009 Share Posted December 7, 2009 hi im trying to get all the userId's that have been inactive in the last 30 days... so far i have SELECT userid FROM users (all the users) and i have SELECT userid FROM transactions WHERE DATE_SUB(CURDATE(), INTERVAL 28 DAY) <= EndAt so i need to exclude the second query from the first... how do i do that and just end up with the userid's of those not been used in the last 28 days (EndAt is a list of all transaction dates) thanks Quote Link to comment https://forums.phpfreaks.com/topic/184279-exlusion/ Share on other sites More sharing options...
Mchl Posted December 7, 2009 Share Posted December 7, 2009 SELECT u.userid FROM users AS u LEFT JOIN (SELECT userid FROM transactions WHERE DATE_SUB(CURDATE(), INTERVAL 28 DAY) <= EndAt) AS t USING (userid) WHERE t.userid IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/184279-exlusion/#findComment-972886 Share on other sites More sharing options...
countdrac Posted December 7, 2009 Author Share Posted December 7, 2009 Thanks for the answer if you have the time could you please explain to me where/how the exclusion takes place. i really need to learn this stuff... not just copy and paste... thanks again Quote Link to comment https://forums.phpfreaks.com/topic/184279-exlusion/#findComment-973089 Share on other sites More sharing options...
Mchl Posted December 7, 2009 Share Posted December 7, 2009 Remove WHERE t.userid IS NULL from this query and see results. This should make it a bit clearer for you. Quote Link to comment https://forums.phpfreaks.com/topic/184279-exlusion/#findComment-973093 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.