Query does not sort, but also does not give an error

This query does not sort on actors

MATCH (a:Actor:Actor)-[r:ACTED_IN]->(m:Movie) 
WHERE m.year=1995
RETURN a{id: id(a), .name, born2: a.born }
      ,r{.role, age: duration.inDays(a.born, date(m.year+"-06-01")).days / 365 }
	  ,m{.title }
ORDER BY m.year,a.born ASC
LIMIT 10

If I change a.born to a.born2 it sorts, should there not be or sorting or an error when using a.born?

That is strange. β€œa” is supposed to be bound to the node, which does not have a β€œborn2” property. β€œborn2” is defined in your map projection, which should not replace β€œa”, so a.born2 should not exist.

Does the following work?

MATCH (a:Actor:Actor)-[r:ACTED_IN]->(m:Movie) 
WHERE m.year=1995
RETURN a{id: id(a), .name, born: a.born } as actor
      ,r{.role, age: duration.inDays(a.born, date(m.year+"-06-01")).days / 365 }
	  ,m{.title } 
ORDER BY m.year,actor.born ASC
LIMIT 10

Or,

MATCH (a:Actor:Actor)-[r:ACTED_IN]->(m:Movie) 
WHERE m.year=1995
WITH *
ORDER BY m.year, a.born ASC
LIMIT 10
RETURN a{id: id(a), .name, born2: a.born }
      ,r{.role, age: duration.inDays(a.born, date(m.year+"-06-01")).days / 365 }
	  ,m{.title }

In the latest release you can now use order by, limit, and skip without a preceding WITH.

yes both seem to sort on actors

1 Like