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] Link to comment https://forums.phpfreaks.com/topic/21937-problem-with-short-sql-query/ 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. Link to comment https://forums.phpfreaks.com/topic/21937-problem-with-short-sql-query/#findComment-98136 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. Link to comment https://forums.phpfreaks.com/topic/21937-problem-with-short-sql-query/#findComment-98679 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. Link to comment https://forums.phpfreaks.com/topic/21937-problem-with-short-sql-query/#findComment-98693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.