Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Latest commit

 

History

History
81 lines (59 loc) · 1.75 KB

simple.adoc

File metadata and controls

81 lines (59 loc) · 1.75 KB

Tests for simple select queries

These tests cover single table selects and basic conditions.

PoC

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

Comparing SQL with Cypher examples

Sources of the following examples are from Comparing SQL with Cypher.

Find all Products

Select and Return Records

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

Field Access, Ordering and Paging

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