I am using MySQL (MyISAM) 5.0.41 and I have this query:
SELECT `x`.`items`.id, `x`.`items`.name, COUNT(*) AS count
FROM `x`.`items` INNER JOIN `x`.`user_items`
ON `x`.`items`.id = `x`.`user_items`.item_id
GROUP BY name HAVING count > 2 ORDER BY count DESC
I have about 36,000 users, 175,000 user_items and 60,000 items which are constantly added to. So this query is getting a bit slow...
Is it better to:
- Have a
count
field initems
and update that periodically (say each time a user adds an item) - or run the query like this (slowly)..
Or is there any SQL that will populate the count field for me?
Thanks