ok Posted September 6, 2008 Share Posted September 6, 2008 Hi guys i have these fields below, id | invited_by | tota l --------------------------- 1 | anna_anna | 2 2 | iridion_iridion | 2 3 | solid_solid | 0 4 | anna_anna | 2 5 | iridion_iridion | 3 6 | solid_solid | 0 I want to get the maximum value of the column 'total' which is 3 and under the name of iridion_iridion I have these codes below, $query = "SELECT invited_by, MAX(total) AS total FROM winner_tmp GROUP BY invited_by"; $result = mysql_query($query) or die("Problem with the query: $query on line " . __LINE__ . '<br>' . mysql_error()); $row = mysql_fetch_array($result); But it did not show the right result that i need. Can you show me the right SELECT for this please. Thank you. Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 6, 2008 Share Posted September 6, 2008 I'm pretty sure you have to use a GROUP BY with the MAX() function. And that won't help you in this case because you need other data from that row any way. Just order the results from highest to lowest and use LIMIT to get the top record SELECT invited_by, total FROM winner_tmp ORDER BY total DESC LIMIT 1 Quote Link to comment 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.