Combining results with Cypher

The UNION operator can be used to combine the results from two separate queries. This operator is very useful to combine the results of two altogether different queries, which have no common match pattern among them. In this recipe, we will learn the use of the UNION operator via examples.

Getting ready

To work through this recipe, you will need to create the nodes and relationships for which data has been provided with the code files.

How to do it...

We have divided this recipe into the following problem sets:

  • Getting the details: Let's get name of all the airports and flight numbers existing in our graph database:
    MATCH (n:Airport) RETURN n.name AS name UNION ALL MATCH (n:Flight) RETURN n.flight_number AS name

    The following ...

Get Neo4j Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.