Reputation: 119
How do I run union with Memgraph query builder? I've read the documentation at https://memgraph.com/docs/gqlalchemy/how-to-guides/query-builder but I couldn't find anything.
Upvotes: 0
Views: 37
Reputation: 728
Here is the example on how to combine queries and retain duplicates:
match().node(variable="c", labels="Country").return_(results=("c.name", "columnName")).union().match().node(variable="p", labels="Person").return_(results=("p.name", "columnName")).execute()
for this Cypher query:
MATCH (c:Country) RETURN c.name AS columnName UNION ALL MATCH (p:Person) RETURN p.name AS columnName;
Here is the example to combine queries and remove duplicates:
match().node(variable="c", labels="Country").return_(results=("c.name", "columnName")).union(include_duplicates=False).match().node(variable="p", labels="Person").return_(results=("p.name", "columnName")).execute()
for this Cypher:
MATCH (c:Country) RETURN c.name AS columnName UNION MATCH (p:Person) RETURN p.name AS columnName;
Here is the documentation on UNION
clause in Cypher - https://memgraph.com/docs/cypher-manual/clauses/union
Upvotes: 1