Search code snippets, questions, articles...

Sort nodes in descending order Cypher query neo4j

To order rows in descending order using Cypher query in neo4j graph database, ORDER BY clause can be used. You can understand it using the below example.
MATCH (n)
RETURN n.firstname, n.lastname, n.age
ORDER BY n.age DESC

In the above Cypher query, we are getting firstname, lastname, age property from nodes and sorting them in descending order. We are using the ORDER BY node.property to sort the records and using the DESC keyword to sort in descending order.

MATCH (n:Product)
RETURN n.product_name, n.order_id
ORDER BY n.order_id DESC
LIMIT 5
The above Cypher query will order nodes that have Product label in descending order and return the first 5 nodes from that.
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet