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 shows the Neo4j console depicting the result of the late flight time Cypher query:
ORDER BY on unicode strings: Let's get all the airports in ascending order by
name
:MATCH (f)-[r:ORIGIN]->(x) RETURN DISTINCT x.name ORDER BY x.name
ORDER BY...