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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dbalatero
Forum Newbie
Posts: 6
Joined: Tue Jul 29, 2003 2:15 am

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

Post 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);
?>
rterrar
Forum Newbie
Posts: 8
Joined: Wed Aug 06, 2003 12:32 am

Post 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...
Post Reply