Finding the 10 last from my table

I have a table called tbl_stats with the following fields stat_id, object, amount
I would like to find out how many of the last 10 objects of the same kind in my table that have the amount 1.
Example: If the object is shoes, I would like to find out how many of the last 10 shoes inserted that have the amount set to 1.
I guess it’s pretty easy, but I have tried like 10 times know and can’t make it work. I just can’t find out what way to pick this from my table.
I only have 6 different objects, so I guess I will make 6 different queries for this one, just to make it easier.

Is there a simple way to do this? Then, what would be the easiest way? Any ideas?

You could use something like this, add a UNION ALL for each object

SELECT stat_id
     , object
  FROM tbl_stats
 WHERE object = 'shoes'
 ORDER BY stat_id DESC
 LIMIT 10
UNION ALL
SELECT stat_id
     , object
  FROM tbl_stats
 WHERE object = 'pogo sticks'
 ORDER BY stat_id DESC
 LIMIT 10

Hmmmm, I didn’t get that one. How can I read how many shoes have the amount set to 1 from this?
I just want to read how many of the last 10 shoes have the amount set to 1 from the table.

Sorry - forgot to add that in - you’d need an AND condition on each of those where clauses (WHERE object = ‘shoes’ AND amount = 1)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.