Home > Enterprise >  Ordering your query result by various parameters ordered differently
Ordering your query result by various parameters ordered differently

Time:08-30

I'm starting to learn Neo4j graph database and I see that you can order you returned data by different(unlimited) parameters in different ways. In what cases this kind of ordering would be useful? If you order by different parameters in different orders you will loose correlation between parameters in the rows, as say m.year is ordered in descending order while m.title can be ordered in ascending order. I can think of Analytics queries, where you want to let's say see in one row the latest day that an order has been placed and in another the maximum amount for the order and in another one the max number of items in a order. Many thanks.

CodePudding user response:

I think you got the wrong idea, of how sorting by multiple parameters works in Cypher. When you specify multiple sort parameters, like this:

MATCH (n)
RETURN n.name, n.age
ORDER BY n.age ASC, n.name DESC

The sorting first happens on the basis of age in ascending order, and if there are two result objects having the same age, then they are sorted by name in descending order. So the correlation between the parameters in a row remains intact.

Here's the documentation link.

  • Related