M
M
Messi2017-09-22 09:22:38
MySQL
Messi, 2017-09-22 09:22:38

How to make null values ​​last in the selection?

When I make a request through (new Query()) in Yii2, there is a field in which the value id = null will be.
At the end of the query, when I do an order by, I need to sort so that nulls are at the end.
Just in sql query, I can do it like this: ORDER BY -group.id DESC or using coalesce.
And how to do the same only in ->orderBy(["-group.id" => SORT_DESC])->all(); ?
This field is not accepted.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2017-09-22
@FitTech

In mysql, put "-" (minus) before the sorted field and then put null at the end of the list
order by -id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question