1
votes

How to ORDER BY in Cypher to put 'null' results to back in descending sort? By documentation null results come as the first in descending sort.

MATCH (n:Title) 
WHERE n.primaryTitle STARTS WITH "D"
RETURN n.primaryTitle, n.startYear, n.ratings, n.numberOfVotes 
ORDER BY n.numberOfVotes DESC 
LIMIT 7
1

1 Answers

1
votes

You could coalesce the nulls to zero in the ORDER BY.

MATCH (n:Title) 
WHERE n.primaryTitle STARTS WITH "D"
RETURN n.primaryTitle, n.startYear, n.ratings, n.numberOfVotes 
ORDER BY coalesce(n.numberOfVotes,0) DESC 
LIMIT 7

OR you could simply coalesce the returned attribute.

MATCH (n:Title) 
WHERE n.primaryTitle STARTS WITH "D"
RETURN n.primaryTitle, n.startYear, n.ratings, coalesce(n.numberOfVotes,0) 
ORDER BY n.numberOfVotes DESC 
LIMIT 7