SQL joins Problem

Hi I’m trying to learn SQL and I am learning about joins. I have come across a problem that I can’t seem to find a solution for.

I have 2 tables orders and order_items. I wanted to display the results for total orders and total quantity. I expected the results to display 4 total orders and 10 total quantity. But it shows 7 total orders and 10 total quantity.

Orders Table

orderstable

Order Items Table

orderitems

my query statement: SELECT COUNT(orders.orders_id) AS 'Total Orders', SUM(order_items.quantity) AS 'Total Products' FROM orders INNER JOIN order_items ON orders.orders_id = order_items.

I’ve been trying to get 4 Total Orders while also joining the other table for Total Products ordered but can’t find a solution. Any help would be much appreciated

SELECT COUNT(DISTINCT orders.orders_id) AS 'Total Orders'
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.