0
I recently opened a question in the stack overflow, how do I get the highest id with a select and status = 1.
Question link: Get higher and lower id with status = 1
Well, now my doubt is contrary, how do I get the smallest id with status = 1.
Thank you.
SELECT * FROM table WHERE status = 1 ORDER BY id ASC
– user28595
Thank you Diego!
– Gonçalo
Gonçalo, is the same logic of the other answer. In the first, only changes the
DESC
(Descending) byASC
(ascending). In the second,MAX( )
of the answer from there picks up the biggest, in his place you use theMIN( )
to catch the little one.AVG( )
It’s to get the average, and so on. All questions are welcome, but if you also give a tip in the documentation, it is easier even for you to know where to find something at the time you need. If you still can’t solve it, leave a comment.– Bacco
I edited your other question and the answers, to facilitate. Now this with the two questions answered in the same place, and with examples.
– Bacco
In fact, the author of the old question "what is the purpose of DESC" was enough, although this has already been explained. I think by default the order of Mysql is ASC, so removing DESC would show the order you want, without even the need to add ASC. I think that trial and error can be a good way, at least to learn what makes each item there. Go "destroying" the code learns, at least something, what each thing does. The documentation will be useful (and more meaningful) after knowing more or less what each thing does, ie every thing destroyed does.
– Inkeliz