Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information

Neo4j:Basics - Match

From NoSQLZoo
Revision as of 11:18, 15 October 2018 by 40166222 (talk | contribs) (temp)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Every Greek deity is known for having certain roles. The example shows the roles of Zeus.
Note that strings (pieces of text that are data) should be either single or double quoted.

Find the roles of Hera.

MATCH (n)
WHERE n:God AND n.name = 'Zeus'
RETURN n.roles;
MATCH (n)
WHERE n:God AND n.name = 'Hera'
RETURN n.roles;

The IN keyword can be used to check if an item is in a list.
This simplifies expressions such as x = a OR x = b OR x = c down to x IN [a, b, c]
The example shows a query that gets all the details of Hera and Zeus

Return all details of Apollo and Artemis.

MATCH (n)
WHERE n:God and n.name IN ['Hera', 'Zeus']
RETURN n;
MATCH (n)
WHERE n:God and n.name IN ['Apollo', 'Artemis']
RETURN n;

Operators can be chained together to check if an object is between two values.
This changes expressions such as a <= b AND b <= c to a <= b <= c
The example returns all the names of any god who has a name starting with the letter A.

Return the names of the gods who's names start with a letter between E and J.

MATCH (n)
WHERE n:God AND "A" < n.name < "B"
RETURN n.name;
MATCH (n)
WHERE n:God AND "E" < n.name < "J"
RETURN n.name;