Page 1 of 1

How to use LIMIT on SUM [MySQL]

Posted: Fri May 18, 2012 2:32 am
by MicroBoy
Hello,

I am trying to get the sum of a specified column, but I want to limit it for 5 first rows. I have tried to use the above code but it is not working, it does not limit but it show sum for all rows. Has anyone know any other methods?

Code: Select all

$sql = mysql_query("SELECT SUM(points) FROM users WHERE u_id = $user_id LIMIT 5");

Re: How to use LIMIT on SUM [MySQL]

Posted: Fri May 18, 2012 7:12 am
by pbs
You need to use GROUP BY clause, if you want user wise SUM(points) with LIMIT