tpimental Posted May 30, 2007 Share Posted May 30, 2007 I've been struggling with this query for way too long and decided I needed some help. Seems simple enough, but I get 0 results. I'm trying to get the latest date of a set of IDs (loc_id) in a report set only when that date is older than 1 year. (mysql version 4.0.27) SELECT Max( report_date ) AS LatestDate, loc_id FROM report_index WHERE 'LatestDate' < curdate( ) - INTERVAL 365 DAY GROUP BY loc_id LIMIT 0 , 500 Table looks something like this: loc_id report_date 1 12/13/2001 2 3/4/2003 2 12/13/2001 3 6/4/2003 3 6/4/2003 4 3/6/2003 4 3/6/2003 5 3/14/2003 5 3/14/2003 5 9/8/2003 5 9/8/2003 Quote Link to comment https://forums.phpfreaks.com/topic/53490-solved-help-with-max-dates/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 30, 2007 Share Posted May 30, 2007 unquote LatestDate in the WHERE clause: WHERE LatestDate < CURRENT_DATE - INTERVAL 1 YEAR Quote Link to comment https://forums.phpfreaks.com/topic/53490-solved-help-with-max-dates/#findComment-264406 Share on other sites More sharing options...
tpimental Posted May 30, 2007 Author Share Posted May 30, 2007 Yah, I tried that. Got this error: #1054 - Unknown column 'LatestDate' in 'where clause' Quote Link to comment https://forums.phpfreaks.com/topic/53490-solved-help-with-max-dates/#findComment-264409 Share on other sites More sharing options...
bubblegum.anarchy Posted May 30, 2007 Share Posted May 30, 2007 heh... SELECT Max( report_date ) AS LatestDate, loc_id FROM report_index GROUP BY loc_id HAVING max(report_date) < CURRENT_DATE - INTERVAL 1 YEAR LIMIT 0 , 500 Quote Link to comment https://forums.phpfreaks.com/topic/53490-solved-help-with-max-dates/#findComment-264426 Share on other sites More sharing options...
tpimental Posted May 30, 2007 Author Share Posted May 30, 2007 That did it! Thanks B.A. Quote Link to comment https://forums.phpfreaks.com/topic/53490-solved-help-with-max-dates/#findComment-264637 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.