Thursday 8 August 2013

SQL: how do i find customer orders with customers?

SQL: how do i find customer orders with customers?

I have two tables: 1. customer 2. customer_order
Customer table contains customer data(duh) and customer_order contains all
the orders. i can join them on customer.id=customer_order.id_customer.
All fine, but now i want a query, where i have all the customer ids, and
next the orders(customer_order.id) which these customers made (with order
date)
like this:
customer 100 order 4, order 5, order 9
customer 101 order 7, order 8, order 15
I have this, but doesn't give me the result, it puts all the customer ids
with an order on different rows:
SELECT c.id, c.firstname, co.id
FROM customer c
JOIN customer_order co
ON c.id=co.id_customer
;

No comments:

Post a Comment