So, I have two tables,
orders and I want to get all orders associated with a customer.
The tables look like this:
customer_no order_no 1027 V327 1027 V391 1028 V400 etc..
order_no article1 article2 size order_date quantity V327 Jeans Black 36 20150101 2 V327 Shirt Blue L 20150101 1 V327 Shirt White L 20150101 2 V391 Jeans Red 34 20150202 3 V400 Shirt Green 32 20150226 2 etc..
Now, I currently use the following query, but it is dog slow and I just know I'm approaching this wrongly. I feel like it should be possible to solve this with a join somewhere, but for the life of mine, I just cannot figure this one out.
SELECT article1, article2, size, order_date, SUM(quantity) FROM orders WHERE order_no IN ( SELECT order_no FROM customers WHERE customer_no = '1027' ) GROUP BY article1, article2, size, order_date, SUM(quantity)
The output for customer 1027 is (and should be):
article1 article2 size order_date SUM(quantity) Jeans Black 36 20150101 2 Shirt Blue L 20150101 1 Shirt White L 20150101 2 Jeans Red 34 20150202 3
Does anyone have a better way of solving this? Performance is my main issue here.