Page 1 of 1

MySQL error: Invalid use of group function... help!

Posted: Wed Aug 06, 2003 5:49 pm
by dbalatero
I have this SQL, yet it returns an error: Invalid use of group function. Any ideas why?

<?php
$sql = "SELECT i.image_id, TRUNCATE(SUM(r.rating) / COUNT(*), 2) AS realrating
FROM images i, rating r
WHERE (i.category_id = '$currCat') AND (i.image_id = r.image_id)
AND (TRUNCATE(SUM(r.rating)/COUNT(*), 2) < '$currRanking')
AND (i.validated = '1') GROUP BY i.image_id LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
?>

Posted: Wed Aug 06, 2003 11:17 pm
by rterrar
We can start here...
If the MySQL server is running in ansi mode you have to include the 'realrating' in the GROUP BY clause. Not doing this is, I think:)), unique to MySQL.
And if that's not it I'll think some more...