I have a customer table (id, name, surname) and an order table (id, quantity, date, customer_id), how can I get the data of the customer who made the cheapest order on a given date? I can't use INNER JOIN, only subqueries. If I use the MAX(amount) in the SELECT I get a figure, but I need it to return all the fields so that I can then compare the customer id.
Edit to put what I'm trying. The code has to be with nested queries, and my mental block has led to this horror:
SELECT *
FROM cliente c
WHERE c.id=(SELECT pedido.id_cliente
FROM pedido
WHERE (SELECT MIN(cantidad)
FROM pedido
WHERE (SELECT *
FROM pedido
WHERE year(fecha)=1999
)
)
);
So first, quickly and running this occurs to me
Or if you prefer with subquery
UPDATE
As capovawi correctly points out in his comment, there is a problem with the sentence in case there are several clients with a minimum order.
The query that I believe would result correct in all scenarios is