O'Reilly logo

Neo4j Cookbook by Ankur Goel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required