In SQL, how do I get all rows where a column's value is the lowest in the table?
This may be what you're asking for:
SELECT product_id FROM table WHERE weight = (SELECT MIN(weight) FROM table);
As you might guess, this will select all prodict_id
s where the weight is equal to the minimum weight in the table.
Not sure which one exactly you want, but either of these should do the trick:
SELECT product_id, MIN(weight) FROM table WHERE 1 GROUP BY product_id
(List all product IDs and the minimum weight per product ID)
SELECT product_id, weight FROM table WHERE weight = (SELECT min(weight) FROM table)
(Find all product IDs where the weight equals the minimum weight)
SELECT min(weight) FROM table;
(Find the absolute minimum weight, and that's that)