I am trying to use a subquery to retrieve the oldest order for each customer. I want to select email_address
, order_id
, and order_date
Tables:
customers(customer_id, email_address)
orders(order_id, order_date, customer_id)
What I've tried:
I can get either the order_id
or the order_date
by doing
SELECT email_address,
(SELECT order_date /* or order_id */
FROM orders o
WHERE o.customer_id = c.customer_id
ORDER BY order_date LIMIT 1)
FROM customers c
GROUP BY email_address;
but if I try to do SELECT order_id, order_date
in my subquery, I get the error:
Operand should contain 1 column(s)