I have three queries that are combined with a UNION clause:
CYPHER 2.0
START user=node:User(Id="2")
MATCH (user)-[:FOLLOWS_USER]->()-[:SHARES]->(post)-[?:ORIGINAL]->(original)
WHERE original is null
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
UNION
MATCH (user)-[:FOLLOWS_USER]->()-[:LIKES]->(post)
WITH post, count(post) as likes
WHERE likes >= 0
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
UNION
MATCH (user)-[:FOLLOWS_USER]->()-[:SHARES]->(post)-[repost:ORIGINAL]->()
WITH post, count(repost) as reposts
WHERE reposts >= 0
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
ORDER BY post.CreationTime desc
SKIP 0
LIMIT 100;
I want to SKIP, LIMITand ORDER BYapplied to a set of results of the whole , not to individual needs. I also believe that it works in SQL. I think, however, that this is not the case in Neo4j, since I can just drop it descout ORDER BY, and the order remains the same.
Is this intended behavior? Is there a way to write a query that I could use SKIP, LIMITand ORDER BYto the entire set of results?
I'm also not sure that I need to repeat the line START user=node:User(Id="2")in each of the subqueries, since a query in version 2.0 can start without a START clause. Should I repeat it?
Neo4j UNION, IMHO.