I have a table called "trails" inside the table I have 3 columns called "id", "name" and "grading".
I have the following query which gives me the last 5 rows of a specific trail name based on the id. This works perfectly but now I need to get the sum total of the 5 results in the grading column?
SELECT * FROM `trails` WHERE `name` = "Free Flow" ORDER BY `id` DESC LIMIT 5
grading) FROM (SELECT ...) AS dataidcolumn is often meaningless. It might be the insertion order, but this isn't actually guaranteed. And since db ids have no real meaning to the world outside, why would anybody else care about ordering by id? What do you mean by "last 5 rows"? Last 5 inserted - do you have a timestamp to record this? Last 5 with activity (ie, a row was updated, changinggrading)? Rely on ids for only one thing - uniqueness (that is, only use them inORDER BYs as a way to make sorts stable - you should have something else as the first sort column).