Reputation: 3612
I've got 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 the SKIP
, the LIMIT
and the ORDER BY
to apply to the whole result set, instead of the individual queries. I believe that's also the way it works in SQL. I think, however, that this is not the case in Neo4j, since I can just drop desc
from the ORDER BY
and the order remains the same.
Is this the intended behaviour? Is there a way I can write the query so that I can apply the SKIP
, the LIMIT
and the ORDER BY
to the whole result set?
I'm also not sure if I have to repeat the line START user=node:User(Id="2")
in each of the subqueries, since a query in 2.0 can start without a START clause. Do I have to repeat it?
Neo4j documentation is bit vague on the UNION
keyword, IMHO.
Upvotes: 4
Views: 974
Reputation: 6331
this is not yet supported, since before that there needs to be support for subqueries in order to implement things correctly.
Upvotes: 1