I have this query which returns the top 10 selling products, and is used on the homepage:
SELECT a.id, a.title, SUM(b.sold) as 'sold' FROM products a
LEFT JOIN stock b ON b.product_id = a.id
GROUP BY a.id ORDER BY sold DESC LIMIT 10
This information doesn't need to be current - it only needs to update maybe once a day. So I had two questions, really:
1) Considering this is evaluating the sold SUM of every single product (from a stock table where each product has multiple rows), is this a computationally expensive query - or rather would it be if this was a large database?
2) Could MySQL cache this query and only update it once per day? I am aware it has a query cache which it uses by default, but according to that this query would be invalidated every time the number of sold items changes.
Am just looking for ways to be more efficient, to be honest.