WHERE Clause
Simple WHERE Clause
MATCH (p:Person)
WHERE p.name = 'Alice'
RETURN p
MATCH (p:Person)
WHERE p.age > 30
RETURN p
Complex WHERE Clause
MATCH (p:Person)
WHERE p.age >= 25 AND p.age <= 35 AND p.city = 'Beijing'
RETURN p
Comparison Operators in WHERE Clause
| Operator | Description |
|---|---|
| = | Equals |
| != or <> | Not equals |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal |
| <= | Less than or equal |
| IS NULL | Null check |
| =~ | Regex match |
| STARTS WITH | String starts with |
| ENDS WITH | String ends with |
| CONTAINS | String contains |
DELETE and REMOVE
DELETE
// Delete node (must delete relationships first)
MATCH (n:Person {name:"wzk1"})
DELETE n
// Use DETACH DELETE to force delete node and all its relationships
MATCH (n:Person {name:"wzk1"})
DETACH DELETE n
REMOVE
Remove properties and labels from nodes or relationships:
MATCH (person:Person {name:"wzk4"})
REMOVE person.cid
SET
Add properties to existing nodes or relationships:
MATCH (person:Person {cid:1})
SET person.money = 3456, person.age = 25
ORDER BY
MATCH (person:Person)
RETURN person.name, person.money
ORDER BY person.money DESC
SKIP and LIMIT
Pagination query:
MATCH (person:Person)
RETURN ID(person), person.name, person.money
ORDER BY person.money DESC
SKIP 4 LIMIT 2
Pagination formula:
- Page 1:
SKIP 0 LIMIT 10 - Page 2:
SKIP 10 LIMIT 10 - Page 3:
SKIP 20 LIMIT 10