Welcome to this Cypher course! Over the next ten days, you’ll learn:

  1. Basics of Cypher
  2. Filtering Results
  3. Structuring Data
  4. Dealing with Cases and Duplicates
  5. Lists and Aggregating Functions
  6. Advanced Queries 1
  7. Advanced Queries 2
  8. Advanced Queries 3
  9. Modifying and Entering Data
  10. Constraints and Indexing

Let’s dive right in! Cypher is a declarative query language designed to efficiently handle querying graph databases. Otherwise complex problems can be easily solved with an elegant Cypher query. Here is a sneak peak of what’s coming:

MATCH (country:Country)
WHERE country.name CONTAINS "c"
RETURN country.name
ORDER BY country.name
LIMIT 2;

Being a declarative language, Cypher expresses what to retrieve, but not how to retrieve it. You can think of Cypher as mapping an English language sentence structure to patterns found in graphs. The nouns in English are nodes in the graph, and the verbs relationships between them. For example; “a person has a dog” can be expressed with: (:Person)-[HAS]->(:Dog).

Through this email course, we will explore the Europe road network dataset. Graph Schema Image

The graph consists of 999 major European cities from 39 countries in total. Each city is connected to the country it belongs to via an edge of type In_. There are edges of type Road connecting cities less than 500 kilometers apart. Distance between cities is specified in the length property of the edge.

Let’s start with something simple. How would one return all the countries from this dataset?

MATCH (country:Country)
RETURN country.name;
  • MATCH gets all the countries and saves them to the variable country
  • RETURN returns the names of the countries as rows in a table

To return all the cities, you only need to change the label Country to City. You can also filter specific results by specifying properties. The following query will only return the city named London:

MATCH (london:City {name: 'London'})
RETURN london.name;

Head over to the playground where you can learn more and write your queries from the comfort of your browser.

Tomorrow you’ll learn about filtering, ordering and limiting the number of results that are returned!

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.