R
R
rain1392021-02-25 22:02:39
MySQL
rain139, 2021-02-25 22:02:39

How to make a sql query so that goods that are not in stock always show at the end?

There is a table where if stock > 0 then available
. As in a query with Order for other columns (for example, id), make records with stock=0 always show at the end, no matter what Order I have.

For example: ORDER by id asc, stock desc - a trivial action does not fit, but I'm dumbing down something... please tell me
SELECT * FROM `products` ORDER by id asc


Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-02-25
@rain139

ORDER BY `stock` = 0, `id`
But the index will stop working when sorting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question