Jump to content

Archived

This topic is now archived and is closed to further replies.

bwaxse

Problem with short sql query

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Well, if you just need one user, you can use the MAX() function instead, with a GROUP BY.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You'd need a GROUP BY sUserName in any case.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.