dhimo Posted August 31, 2007 Share Posted August 31, 2007 HelloI have two tables 1. products 2. orders in a mysql databaseHow can i select the 5 top sold products from orders? Orders table holds product_id and the quantitythanks Link to comment Share on other sites More sharing options...
justsomeguy Posted August 31, 2007 Share Posted August 31, 2007 If it's a recent version of MySQL you can use a subquery. I think this would work. SELECT * FROM products WHERE product_id IN (SELECT product_id, SUM(quantity) FROM orders GROUP BY product_id ORDER BY SUM(quantity) DESC LIMIT 5 ) Link to comment Share on other sites More sharing options...
dhimo Posted September 1, 2007 Author Share Posted September 1, 2007 mysql says that its not supported. I guesss its not a recent version. any other idea Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.