I have a table called books
which has a integer column ordering
, and created_at
column which is date time.
I would like to get the null rows of ordering to come on the top with the descending order in which they are created, after that i would like to get the non null ordering rows in ascending order.
Here's the query I have tried
select * from books order by ordering asc nulls first;
I am getting null ordering rows on the top, but those are in ascending order. Is there a way I can get descending order of null rows based on created_at desc and then use the ordering column to sort the remaining rows in ascending order
The relevent Rails query is
Book.order('ordering ASC NULLS FIRST')