P
P
prostovlad2019-05-18 12:30:37
MySQL
prostovlad, 2019-05-18 12:30:37

How to sort database by two fields?

Good afternoon, there are 2 fields in the table by which you need to sort
category_id and cname
in category_id can be empty or some kind of digital value, names are written in cname.
you need to sort so that it would first give out empty spaces from category_id corresponding to the value in cname alphabetically, and then where there are values ​​in category_id, also in accordance with cname alphabetically
, I tried it and so ORDER BY `category_id`, `cname` and so ORDER BY ` cname`, `category_id` does not work properly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-05-18
@Rsa97

ORDER BY `category_id` IS NOT NULL, `cname`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question