bwaxse Posted September 25, 2006 Share Posted September 25, 2006 Hello all,I get "Invalid use of group function" with this query and don't know why.I'm trying to look through a database of entries to find the user with the most entries and get the name and the number. Thanks![code]$sql = "SELECT sUsername, COUNT(sUsername) FROM tbl_questions WHERE sSchoolID = ".$_SESSION['schoolid']." ORDER BY COUNT(*) DESC LIMIT 0,1";[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted September 25, 2006 Share Posted September 25, 2006 Well, if you just need one user, you can use the MAX() function instead, with a GROUP BY. Quote Link to comment Share on other sites More sharing options...
Gaoshan Posted September 26, 2006 Share Posted September 26, 2006 Do what fenway said.Anyway, just for your information the reason you are having that problem is that you are mixing a GROUP column (in your case COUNT) with non-group columns and not using a GROUP BY clause. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 26, 2006 Share Posted September 26, 2006 You'd need a GROUP BY sUserName in any case. 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.