Kristian
Kristian

Reputation: 21840

neo4j return 1 node with maximum property value

I have a root "company" node, and it will have several relating "report" nodes, each of which has a timestamp property (millisec).

I want to get the "newest" report node for a company, which basically translates to "get 1 node where max(x)" but I dont know if that is possible in cipher

in theory, I could do the following

match (c:company)->(r:report) WHERE r.timestamp order by DESC LIMIT 1

But i want to also be able to get other types of the "newest" nodes. Ultimately I want to get this type of results:

(company)-->(Report [newest version])
         -->(twitterCountObject [newest version])
         -->(employeeCountObject [newest version])

How do I accomplish this in cypher?

Upvotes: 2

Views: 1280

Answers (1)

cybersam
cybersam

Reputation: 67044

You were close. Something like this should work:

MATCH (c:Company {name: "ABC"})-->(r:Report),
      (c)-->(t:TwitterCount),
      (c)-->(e:EmployeeCount)
RETURN c, r, t, e
ORDER BY r.timestamp DESC, t.timestamp DESC, e.timestamp DESC
LIMIT 1;

Upvotes: 3

Related Questions