Get smaller id with status = 1

Asked

Viewed 39 times

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

  • Thank you Diego!

  • 2

    Gonçalo, is the same logic of the other answer. In the first, only changes the DESC (Descending) by ASC (ascending). In the second, MAX( ) of the answer from there picks up the biggest, in his place you use the MIN( ) 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.

  • I edited your other question and the answers, to facilitate. Now this with the two questions answered in the same place, and with examples.

  • 1

    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.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.