Welcome to this Cypher course! Over the next ten days, you’ll learn:
- Basics of Cypher
- Filtering Results
- Structuring Data
- Dealing with Cases and Duplicates
- Lists and Aggregating Functions
- Advanced Queries 1
- Advanced Queries 2
- Advanced Queries 3
- Modifying and Entering Data
- 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.
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 countryRETURN
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!