How to use two database columns as a sort criteria for a Query?

Asked

Viewed 80 times

0

Hello,

Could you help me with this question? I’m making a query in MYSQL you need to search the records database and sort them by two different columns using ORDER BY. I’m using the query following, but does not function as expected.

SELECT * FROM customers ORDER BY status = 'Desenvolvimento', created DESC limit $inicio, $quantidade_pg "

For the column "status" I have two possible values, "Development" and "Completed". The idea was to sort the requests by "Development" and then sort them by the "created" column that has the creation date of the record in the database. Can you help me with the right path to this? I need to use subquery for that kind of query? Remember, I’m using this query within a Javascript, so it has the codes in the start and quantity_pg variables.

  • 1

    The syntax ORDER BY X = Y does not exist. If you just want to sort by status, it’s just ORDER BY status; the part of the comparison, = 'Desenvolvimento', it’s hanging over and it doesn’t make sense there.

1 answer

0


Use this instruction in your Order by

...ORDER BY STATUS DESC, CREATED

This will sort everything by STATUS (DESC) first, and then by CREATED (ASC)

Browser other questions tagged

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