KEMBAR78
? Cypher (CQL) MATCH Query - Beginner-Friendly Cheat Sheet | PDF | Operations Research | Information Technology Management
0% found this document useful (0 votes)
5 views5 pages

? Cypher (CQL) MATCH Query - Beginner-Friendly Cheat Sheet

Uploaded by

arnobyt23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

? Cypher (CQL) MATCH Query - Beginner-Friendly Cheat Sheet

Uploaded by

arnobyt23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

📘 Cypher (CQL) MATCH Query –

Beginner-Friendly Cheat Sheet

🚀 What is Cypher MATCH?


Cypher is the query language used in Neo4j (a graph database).​
The MATCH keyword is used to find patterns in your graph: nodes, relationships, and how they
are connected.

🧱 Graph Elements
🔹 Nodes
●​ Entities in your graph (e.g., Person, Concept, Document)​

Syntax:​

cypher​
CopyEdit​
(variable:Label {propertyKey: value})
Example:​

cypher​
CopyEdit​
(scientist:Person {id: "Albert Einstein"})

●​

🔹 Relationships
●​ Connections between nodes.​

Syntax:​

cypher​
CopyEdit​
(a)-[:RELATION_TYPE]->(b)

●​
○​ : defines the relationship type​

○​ Arrows indicate direction​

🔄 Arrow Directions
Syntax Meaning

(a)-[:REL]-> a points to b (outgoing)


(b)

(a)<-[:REL]- b points to a (incoming)


(b)

(a)-[:REL]-( direction doesn't matter


b) (any)

🔍 Interpreting Your Query


Your full Cypher query:
cypher
CopyEdit
MATCH (relativity:Concept {id: "Theory Of Relativity"})
<-[:KNOWN_FOR]- (scientist:Person)
RETURN scientist

🔹 Line-by-line breakdown:
1.​ MATCH​
Start a pattern search in the graph.​
2.​ (relativity:Concept {id: "Theory Of Relativity"})​

○​ Look for a node:​

■​ Labeled Concept​

■​ With id = "Theory Of Relativity"​

○​ Assign it to variable relativity​

3.​ <-[:KNOWN_FOR]-​

○​ Find all incoming relationships of type KNOWN_FOR​

○​ These point from a person to the concept.​

4.​ (scientist:Person)​

○​ The other node in this relationship​

○​ Labeled Person​

○​ Assign it to variable scientist​

5.​ RETURN scientist​

○​ Return all matched people who are known for the Theory of Relativity​

🔧 Common Syntax Structure


✅ Correct:
cypher
CopyEdit
(variableName:Label {propertyKey: value})

e.g.:
cypher
CopyEdit
(scientist:Person {id: "Einstein"})

❌ Incorrect:
cypher
CopyEdit
(Label:variableName) ← Wrong order

e.g.:

cypher

❌ Invalid
CopyEdit
(Person:scientist) ←

🧪 Bonus Example
To find all documents that mention the scientist:

cypher
CopyEdit
MATCH
(doc:Document)-[:MENTIONS]->(scientist:Person)-[:KNOWN_FOR]->(concept:
Concept {id: "Theory Of Relativity"})
RETURN doc.source, scientist.id

🧠 TL;DR Summary
●​ MATCH = search pattern​

●​ (variable:Label) = node​

●​ [:RELATION] = relationship​
●​ -> / <- = relationship direction​

●​ RETURN = return matched items​

●​ Node variable name goes before label: scientist:Person, not Person:scientist​

You might also like