Interpret the query below.

CREATE (p:Person {name: “Jennifer”})-[rel:LIKES]->(g:Technology {type: “Graphs”})

Nodes and relationships make up the building blocks for graph patterns. The pattern above can be interpret as create a new relationship between Jennifer (a person) and Graphs (a type of technology), where the relationship is LIKES. Overall, Jennifer likes Graphs.

MATCH and RETURN command.

Note that RETURN is required when you perform read procedures but it’s not necessary for write procedures.

The simplest query to return all nodes that are labelled Person:

MATCH (p:Person) RETURN p

To find a person node with a specific name:

MATCH (jenn:Person {name: ‘Jennifer’}) RETURN jenn

To find which company Jennifer works at:

MATCH (jenn:Person {name: ‘Jennifer’})-[rel:WORKS_FOR]->(work:Company) RETURN work (RETURN work.name if you just want to return the name of the company)

Aliasing return values:

You can use AS to alias property names with a cleaner names like SQL.

MATCH (kristen:Customer {name:’Kristen’})-[rel:PURCHASED]-(order:Order)
RETURN order.orderId AS OrderID, order.orderDate AS `Purchase Date`, kristen.customerIdNo AS CustomerID, order.orderNumOfLineItems AS `Number Of Items`

Ryan

Ryan

Data Scientist

Leave a Reply