MySQL select SUM of results with a LIMIT MySQL select SUM of results with a LIMIT mysql mysql

MySQL select SUM of results with a LIMIT


select sum(price) from (select items.price from items order by items.price desc limit 3) as subt;


LIMIT affects the number of rows returned by the query and SUM only returns one. Based on this thread you might want to try:

SELECT sum(price) FROM (SELECT price      FROM items      ORDER BY price DESC      LIMIT 3) AS subquery;


Just use a sub-select:

select sum(prices) from (SELECT SUM(items.price) FROM items ORDER BY items.price LIMIT 3) as prices