Book Image

Learning Cypher

By : Onofrio Panzarino
Book Image

Learning Cypher

By: Onofrio Panzarino

Overview of this book

Table of Contents (13 chapters)


If you have experience with SQL, then sorting with Cypher is exactly the same as sorting with SQL. We can use the ORDER BY clause to specify the columns to be used for sorting, as shown in the following query:

MATCH (b:Book)
WHERE ANY ( tag IN b.tags WHERE tag IN ['drama'] )
RETURN b.title
ORDER BY b.title

The preceding query looks for books tagged drama in the database, then sorts them by title, and returns the first five book entries found. We can note the following:

  • The ORDER BY clause follows the RETURN clause

  • This clause is above the LIMIT or SKIP clause so that we can sort the data before limiting our page

The result set is as follows:

| b.title                     |
| "A Lover's Complaint"       |
| "A Midsummer Night's Dream" |
| "All's Well That Ends Well" |
| "Anthony and Cleopatra"     |
| "As You Like It"            |

A descending sort

To sort inversely, just postpone the DESC...