I have a query. I just would like to get the number of orders for each distinct customer. But the results give me very high numbers, most probably somehow summing up all ids. What am I missing?
SELECT COUNT(b.order_id) AS number_of_orders_for_each_distinct_customer, a.customer_id FROM messages a INNER JOIN orders b ON a.customer_id = b.customer_id INNER JOIN order_items c ON c.order_id = b.order_id INNER JOIN products d ON c.product_id = c.product_id GROUP BY a.customer_id