In SQL, how do I get all rows where the column value is the lowest in the table?

I am new to SQL, I use this query to find the minimum value in the weight field of my table.

SELECT product_id, MIN(weight) FROM table WHERE 1; 

It shows one field with a minimum value, but only one? But I have many products with the same minimum weight. Is there a way to indicate that I need to show all other products?

+6
sql database aggregate-functions
source share
3 answers
 select * from table where weight = (select MIN(weight) from table) 
+16
source share

This may be what you are asking for:

 SELECT product_id FROM table WHERE weight = (SELECT MIN(weight) FROM table); 

As you might have guessed, this will select all prodict_id , where the weight is equal to the minimum weight in the table.

+3
source share

Not sure which one you want, but any of them should do the trick:

 SELECT product_id, MIN(weight) FROM table WHERE 1 GROUP BY product_id 

(List all product identifiers and minimum weight for product identifier)

 SELECT product_id, weight FROM table WHERE weight = (SELECT min(weight) FROM table) 

(Find all product identifiers where weight equals minimum weight)

 SELECT min(weight) FROM table; 

(Find the absolute minimum weight and what)

+1
source share

All Articles