Hi there! I have a table where I have banners added with ID. When someone uses a banner it is added to the database again. So, it is like userx bannery userz bannery etc. I can do count(bannery) to see how many times the banner with ID bannery is in my DB. WHat I need now is to count all the banners by ID and display the top 10 most used banners. Also, this needs to consume as few mysql recourses as possible. I am not sure how can I do that. Any kind of help is much appreciated. Thank you!
Hi Fracisc. Try this: SELECT banner_id_field, COUNT(*) FROM banners_table GROUP BY banner_id_field ORDER BY COUNT(*) DESC LIMIT 10 Code (markup):
Sorry, just edit your code. Usually use a field in mysql function will give less time. SELECT banner_id_field, COUNT(banner_id_field) AS counter FROM banners_table GROUP BY banner_id_field ORDER BY COUNT(banner_id_field) DESC LIMIT 10 Code (markup):