O'Reilly logo

Neo4j Cookbook by Ankur Goel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required