ORDER BY , , . , , , . ? , , .
, .
, :
SELECT product.*, MIN(qty)
FROM product
GROUP BY
type
ORDER BY
qty
, MySQL, / GROUP BY.
, a JOIN, a GROUP BY a PRIMARY KEY, :
SELECT order.id, order.customer, SUM(price)
FROM order
JOIN orderline
ON orderline.order_id = order.id
GROUP BY
order.id
order.customer , order.id, .
qty .
, .
:
SELECT p.*
FROM (
SELECT DISTINCT type
FROM product p
) pd
JOIN p
ON p.id =
(
SELECT pi.id
FROM product pi
WHERE pi.type = pd.type
ORDER BY
type, qty, id
LIMIT 1
)
product (type, qty, id), .