Changing the order of results with Cypher

Cypher is similar to SQL, where the order of the results can be changed using the ORDER BY clause, both in ascending and descending order. In this recipe, we will learn the use of the ORDER BY clause using the instance of the graph we have created.

Getting ready

To work through this recipe, you will need to create the nodes and relationships for which data has been provided with the code files.

How to do it...

We have divided this recipe into the following problem sets:

  • ORDER BY on numerical value: Let's get the delay times of the most delayed flights, along with the flight number and reason for delay:
    MATCH (f)-[r:`DELAYED_BY`]->(x) RETURN f.flight_number,r.time,x.name ORDER BY r.time DESC

    The following screenshot ...

Get Neo4j Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.