I am a newbie to SQL, I am using this query to look for the minimum value in the field weight of my table.
SELECT product_id,
MIN(weight)
FROM table
WHERE 1;
It does show one field with the min value, but only one? But I have many products with the same minimum weight. Is there a way I could specify that I need to show all other products?
The SQL MIN() function with WHERE clauseThe aggregate functions can be used in conjunction with the WHERE clause to gain further insights from our data. One of these is the MIN() function. In SQL, the MIN() function is used to compute the smallest or minimum value of numeric values in a column.
The SQL SELECT TOP Clause The SELECT TOP clause is used to specify the number of records to return. The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number of records can impact performance.
We can use a nested CASE statement to compare the values of multiple columns to get the minimum value. Also, we can use the nested IIF statement.
select * from table where weight = (select MIN(weight) from table)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With