Neo4j Query Cypher Language

The Neo4j has its own query language that called Cypher Language. It is similar to SQL, remember one one thing Neo4j does not work with tables, row or columns it deals with nodes. It is more satisfied to see the data in a graph format rather then in a table format.

Example: The Neo4j Cypher statement compare to SQL

MATCH (G:Company { name:"GeeksforGeeks" })
RETURN G

This Cypher statement will return the “Company” node where the “name” property is GeeksforGeeks. Here the “G” works like a variable to holds the data that your Cypher query demands after that it will return. It will will be more clear if you know the SQL. Below same query is written in SQL.

SELECT * FROM Comapny WHERE name = "GeeksforGeeks";

The neo4j is made for NoSQL database but it is very effective on relational database too, it does not use the SQL language.

ASCII-Art Syntax: The Neo4j used ASCII-Art to create pattern.

(X)-[:GeeksfroGeeks]->(Y)
  • In the Neo4j the nodes are represented by “( )”.
  • The relationship is represented by ” -> “.
  • What kind of relationship is between the nodes are represented by ” [ ] ” like [:GeeksforGeeks]

So above description is helpful to decode the ASCII-Art Syntax given, (X)-[:GeeksfroGeeks]->(Y). Here the X and Y are the nodes X to Y relation kind is “GeekforGeeks”.

Defining Data: Below points will help you to grasp the concept pf Cypher language.

  • Neo4j deals with nodes and the nodes contains labels that could be “Person”, “Employee”, “Employer” anything that can define the type of value field.
  • Neo4j also have properties like “name”, “employee_id”, “phone_number”, basically that will gives us information about the nodes.
  • Neo4j’s relationship also can contain the properties but this is not mandatory.
  • In Neo4j the relationship is like the kind of situation like X works for GeeksforGeeks here the X and the “GeeksforGeeks” is the node and the relation is works for, in Cypher language it will be like.
     (X)-[:WORK]->(GeekfoGeeks).

Note: Here the Company is the node’s label, name is the property of the node

MATCH (G:Company { name:"GeeksforGeeks" })
RETURN G 


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.