Table of Contents
These tests cover single table selects and basic conditions.
The input
SELECT t.a, t.b
FROM `MY_TABLE` AS t
WHERE t.a = 1
will be transpiled to
MATCH (t:MY_TABLE)
WHERE t.a = 1
RETURN t.a, t.b
SELECT 1
RETURN 1
Sources of the following examples are from Comparing SQL with Cypher.
Easy in SQL, just select everything from the products
table.
SELECT p.*
FROM products as p
Similarly, in Cypher, you just match a simple pattern: all nodes with the label :Product
and RETURN
them.
MATCH (p:Product)
RETURN p
More efficient is to return only a subset of attributes, like ProductName
and UnitPrice
.
And while we’re on it, let’s also order by price and only return the 10 most expensive items.
SELECT p.`productName`, p.`unitPrice`
FROM products as p
ORDER BY p.`unitPrice` DESC
LIMIT 10
You can copy and paste the changes from SQL to Cypher, it’s thankfully unsurprising. But remember that labels, relationship-types and property-names are case sensitive in Neo4j.
MATCH (p:Product)
RETURN p.productName, p.unitPrice ORDER BY p.unitPrice DESC LIMIT 10