Is there a way to specify where to place null values in a sorted list?
I have a list I'd like to sort in descending order. I want nodes with date=null to be included, just at the end of the list.
Looking for something like this in cypher:
ORDER BY date DESC NULLS LAST
From Neo4j:
When sorting the result set, NULL will always come at the end of the result set for ascending sorting, and first when doing descending sort.
http://neo4j.com/docs/developer-manual/current/#order-by-ordering-null
You can sort by result of COALESCE.
For example we have the following nodes:
MERGE (A1:Test {name:'a1'})
MERGE (A2:Test {name:'a2', date: 1})
MERGE (A3:Test {name:'a3', date: 2})
MERGE (A4:Test {name:'a4'})
We can sort the following manner:
MATCH (A:Test)
RETURN A.name,
A.date
ORDER BY
COALESCE(A.date, -1) DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With