I have data in two tables. One has order details, the other has product details. The order_details
table references the product
table via the product_id
column. The product
table has columns product_id
and product_name
.
I count sales per product ID like this:
SELECT product_id, COUNT(*)
FROM order_details
GROUP BY product_id
ORDER BY COUNT(*) DESC
and get output like this:
product_id
123 2500
421 1700
111 1040
Now I want to have the names from the product
table instead of the IDs:
apples 2500
banana 1700
pear 1040
How can I do that?