sample table
id | name | price |
-----------------------
1 | john | 300 |
-----------------------
2 | michael | 400 |
-----------------------
3 | michelle | 250 |
-----------------------
I will get the smallest number in the table using this query
SELECT id, name, MIN(price) FROM table
The result will become this:
_______________________
id | name | price |
-----------------------
1 | michelle | 250 |
I want the result will become like this:
id | name | price |
-----------------------
3 | michelle | 250 |
-----------------------
Thanks in advance!
The easiest way to get the id of the smallest number is this:
SELECT Id, name, price
FROM sampleTable
ORDER BY price ASC
LIMIT 1;
If you want to use MIN (as the title states), one way to do it would be this:
SELECT id, name, price
FROM sampleTable
WHERE price = (SELECT MIN(price) from sampleTable)
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