Reputation: 1
I want to Pick a random customer that has done an order, then display a list of ProductName that he/she buys
join orders o on customers.customerNumber = orders.customerNumber
join orderdetails o2 on orders.orderNumber = orderdetails.orderNumber
join products p on orderdetails.productCode = products.productCode
union select status from orders o where status = 'shipped'
order by rand() limit 5;
but got Error
SQL Error [1054][42s22]: unknown column 'orderdetails.productCode in 'on clause'
but I make sure the table there is a column productCode in orderdetails. can someone help me?
Upvotes: 0
Views: 120
Reputation: 1269693
You have given orderdetails
the alias o2
, so that is how the table should be referred to. Similarly for the other tables:
customer c join
orders o
on c.customerNumber = c.customerNumber join
orderdetails o2
on o.orderNumber = o2.orderNumber join
products p
on o2.productCode = p.productCode
Upvotes: 1