SQL , , MySQL, .
"cond = good" , "id" , "cond = good", ? id = 3 id = 2? , ? MySQL , , .
, , .
PostgreSQL , DISTINCT ON ..., . , . DISTINCT ON , .
SQL- , . , , , inner where, .
SELECT *
FROM (
SELECT *, dense_rank() OVER w AS itemrank
FROM items
WHERE product_id = 1 AND items.status = 'in_stock'
WINDOW w AS (PARTITION BY cond ORDER BY price ASC)
) ranked_items
WHERE itemrank = 1;
(http://sqlfiddle.com/#!1/33786/19)
SQL , :
SELECT *
FROM items INNER JOIN (
SELECT cond, min(price) AS minprice
FROM items
WHERE product_id = 1 AND items.status = 'in_stock'
GROUP BY cond
) minprices(cond, price)
ON (items.price = minprices.price AND items.cond = minprices.cond)
ORDER BY items.price;
DISTINCT ON, , .
, DISTINCT ON, . PostgreSQL.
, PostgreSQL , GROUP BY; . , cols, PK . , , , , .
, , , , , , GROUP BY .