'get the name of product with the maximum number of orders
I have 2 tables orders and product as orders has only one field (order_id) and the products have a reference to the order_id,
how to get the name of product with the maximum number of orders
I tried this query
SELECT MAX(mycount)
FROM
(Select products.product_name , count(orders.order_id) mycount
FROM Orders, products
WHERE products.order_id = Orders.order_id
GROUP BY orders.order_id)
but it only gave me the max value, how to add the name field (products.product_name) to the result??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|