Wuhtzu Posted December 4, 2006 Share Posted December 4, 2006 Hey guysI have this pretty ugly MySQL query:[code]SELECT name,id,date,string_length,firstmatch_key,firstmatch_string,secondmatch_key,secondmatch_string,MIN(diff) FROM gorandom_log WHERE string_length=".$string_length." GROUP BY name ORDER BY diff ASC LIMIT 10[/code]The purpose of the query is to select the smallest "diff" for each "name" and them sort them by the diff ascading. My problem is that does not order them by diff...What is wrong with my query and how to correct it?Best regardsWuhtzu Quote Link to comment https://forums.phpfreaks.com/topic/29423-mysql-query-help-group-by-and-order-by/ Share on other sites More sharing options...
artacus Posted December 4, 2006 Share Posted December 4, 2006 Try including the diff field in your results or alias "MIN(diff) AS diff"If that doesn't work, just use a subquery. Quote Link to comment https://forums.phpfreaks.com/topic/29423-mysql-query-help-group-by-and-order-by/#findComment-135020 Share on other sites More sharing options...
Wuhtzu Posted December 4, 2006 Author Share Posted December 4, 2006 "MIN(diff) AS diff" worked perfectly -> Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/29423-mysql-query-help-group-by-and-order-by/#findComment-135027 Share on other sites More sharing options...
artacus Posted December 4, 2006 Share Posted December 4, 2006 You're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/29423-mysql-query-help-group-by-and-order-by/#findComment-135030 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.