For a set of nodes a
from a query (like MATCH (a:Type) WHERE ... WITH a
), I want to find the node(s) that maximize the property a.number
. With max
I can maximize the number itself, but how do I get the whole object a
which maximizes a.number
?
Asked
Active
Viewed 55 times
0

J Fabian Meier
- 33,516
- 10
- 64
- 142
-
How can a node maximize a property? – Martin Preusse Aug 11 '16 at 10:08
1 Answers
1
Do you mean you want to return the node with the largest a.number
?
You can MATCH
the nodes, ORDER BY
number
and RETURN
only one node:
MATCH (a:Type)
RETURN a ORDER BY a.number DESC LIMIT 1

Martin Preusse
- 9,151
- 12
- 48
- 80
-
I thought this would be overkill (sorting the whole list to find the maximal element), but you're right, it works fine. – J Fabian Meier Aug 11 '16 at 10:50