Listing results from a SELECT * statement numerically and choosing the lowest number
I'll thank you guys before hand for helping me out, I can't seem to figure this one out and searching around this site and other search e开发者_运维问答ngines has been frustrating.
I'm running a query on my database, and using SELECT * . Now I'm able to retrieve all the information from the database and list them in ASC order. That's not the problem.
The problem is I cant seem to figure out how to retrieve the lowest number from that search. For example:
If I run the query, and I retrieve the following ID's in ASC order (12,18,22) How can I make it so where my script chooses 12? Or if it was (30,50,52) to choose 30?
If you are selecting everything from your table and say its already in descending order the
SELECT column FROM table
ORDER BY ID DESC
LIMIT 1
Should give you the first row, which is already the min. If you actually just want the minimum value and don't care much for anything else but that value you could try:
SELECT MIN(column) FROM TABLE
How about select min(<ColumnName>) from ..
where <ColumnName>
is the column that contains the number you want to find.
select min(id) from yourtable
精彩评论