mrobinson83 Posted February 3, 2009 Share Posted February 3, 2009 Hi, I am having problems with the following query: SELECT status_lead.lead_id, status_lead.status_id, MAX(status_lead.status_version), lead.Date_Logged FROM status_lead JOIN lead ON status_lead.lead_ID = lead.lead_ID WHERE status_lead.status_id =3 AND lead.Date_Logged BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 2 week ) AND DATE_SUB( CURDATE( ) , INTERVAL 1 week ) GROUP BY status_lead.lead_id The query works but it doesn't seem to apply the "status_lead.status_id =3" part of the statement. The output always seem to show the correct max value for a unique lead however status_id = 1 and not 3 in most cases. I am querying to find the max value of status_version whereby status_id=3, I hope this makes sense. I am pretty sure I am missing some brackets or something somewhere. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/143619-max-function-subquery/ Share on other sites More sharing options...
mrobinson83 Posted February 4, 2009 Author Share Posted February 4, 2009 MYSQL Version - 5.1.11 Link to comment https://forums.phpfreaks.com/topic/143619-max-function-subquery/#findComment-754438 Share on other sites More sharing options...
fenway Posted February 6, 2009 Share Posted February 6, 2009 You've getting funny results because you're including non-group by columns in your select list..that's a no-no. Link to comment https://forums.phpfreaks.com/topic/143619-max-function-subquery/#findComment-755801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.