How to reorder the result of a query if it has a specific result?

Asked

Viewed 15 times

1

I have a query (select nome from coisas;) that returns to me for example:

escova
mesa
cadeira
garfo

How do I make so that if there is a "chair" in the results, it always appears first, and the others do not matter the order, but preferably order by name.

  • I don’t get it, what it’s like SELECT nome FROM coisas and returns several results, can explain better?

  • As per closing link: ORDER BY nome != "cadeira", nome, brings chair first and the rest alphabetical order. If the order of rest does not matter, can simplify: ORDER BY nome != "cadeira" or ORDER BY nome = "cadeira" DESC

  • In this case the order of SELECT no longer does what is necessary? Like SELECT cadeira, escova, mesa, garfo FROM ...

  • @Bacco was exactly what I needed! If you can post as an answer for me to accept. Thank you.

  • Closing as a duplicate causes visitors to find the original answer in the other post, and your question serves as an index. Here we avoid duplicating solutions in different posts for organization (so that all users find the grouped solutions). When you have a little more points you can vote positive for all the answers that help you, even in other posts.

  • Opa, quiet, did not know how to search, but really is duplicated.

  • When you have additional questions about the subject, you can leave a comment here or in the original answers there. And for other questions, feel free to open new posts.

Show 2 more comments
No answers

Browser other questions tagged

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