Neo4j Notes - Cypher (CQL)

Neo4j CQL (Cypher Query Language)

SQL vs CQL

Clauses

node + label + property + relationship

CREATE

CREATE (:)
CREATE (::.....:)
CREATE (:)-[(:)]->(:)

MATCH

image.png

Get all nodes

MATCH ()
eg. MATCH (n) RETURN n

Get all nodes with a label

MATCH (:)
eg. MATCH (movie:Movie) RETURN movie.title

Related nodes

The symbol -- means related to, without regard to type or direction of the relationship.
eg. MATCH (director { name: 'Oliver Stone' })--(movie) RETURN movie.title

Match with labels

Returns any nodes connected with the Person 'Oliver' that are labeled Movie.
eg. MATCH (:Person { name: 'Oliver Stone' })--(movie:Movie) RETURN movie.title

Outgoing relationships

When the direction of a relationship is of interest, it is shown by using -→ or ←-, like this:
Returns any nodes connected with the Person 'Oliver' by an outgoing relationship.
eg. MATCH (:Person { name: 'Oliver Stone' })-->(movie) RETURN movie.title

Directed relationships and variable

eg. MATCH (:Person { name: 'Oliver Stone' })-[r]->(movie) RETURN type(r)

Match on relationship type

Returns all actors that ACTED_IN 'Wall Street'.
eg. MATCH (wallstreet:Movie { title: 'Wall Street' })<-[:ACTED_IN]-(actor) RETURN actor.name

Match on multiple relationship types

Returns nodes with an ACTED_IN or DIRECTED relationship to 'Wall Street'.
eg. MATCH (wallstreet { title: 'Wall Street' })<-[:ACTED_IN|:DIRECTED]-(person) RETURN person.name

Match on relationship type and use a variable

Returns ACTED_IN roles for 'Wall Street'.
eg. MATCH (wallstreet { title: 'Wall Street' })<-[r:ACTED_IN]-(actor) RETURN r.role

RETURN

RETURN ., ........ .

WHERE

WHERE
WHERE

= <> < > <= >=

AND OR NOT XOR

DELETE

Work on node and relationship
DELETE
DELETE ,,

REMOVE

Work on property
Both REMOVE and DELETE should work together with MATCH
REMOVE

SET

SET

Sorting

ORDER BY [DESC]

UNION

two command should return same column name and data type
by UNION we remove duplicates
UNION
by UNION ALL we retain duplicates
UNION ALL

LIMIT & SKIP

return top lines
LIMIT
return bottom lines
SKIP

MERGE = CREATE + MATCH

MERGE (: { : ..... : })

CQL function

你可能感兴趣的:(Neo4j Notes - Cypher (CQL))