I have the following tables(with their columns in brackets):
- products(productID, productName, categoryID)
- categories(categoryID, categoryName)
- customers(customerID, customerName)
- orders(customerID, create_at, productID)
I can successfully use inner join to display all the order details and include the product and customer names.
select products.productName, orders.create_at, customers.customerName
from orders
inner join products on orders.productID=products.productID
inner join customers on orders.customerID=customers.customerID;
Now I want to display only the orders in which the product belongs to category "laptop". And my attempt was the following:
select products.productName, orders.create_at, customers.customerName
from orders
inner join products on orders.productID=products.productID
inner join customers on orders.customerID=customers.customerID where categories.categoryName='laptop';
But this doesn't work and I assume it is because the where clause should be based on a column that belongs to the orders table.
The error I get is the following:
ERROR 1054 (42S22): Unknown column 'categories.categoryName' in 'where clause'
How can I show only orders which products belong to a specific category?