SQL to Cypher Example & Basic usage

#SELECT vs MACTH

in SQL

SELECT *
FROM "Example"
WHERE key = 'Keyword'

in CQL

MATCH (Example: { key: 'Keyword'})
RETURN Example

#Matching connected nodes

SQL Query

SELECT "Email".*
FROM "Person"
JOIN "Email" ON "Person".id = "Email".person_id
WHERE "Person".name = 'Anakin'

Cypher Query

MATCH (person:Person { name: 'Anakin' })-[:email]->(email)
RETURN email

#Where

SQL Query

SELECT *
FROM "Person"
WHERE "Person".age > 35 AND "Person".hair = 'blonde'

Cypher Query

MATCH (person:Person)
WHERE HAS (person.name) AND person.age > 35 AND person.hair = 'blonde'
RETURN person

#Return

GROUP BY and ORDER BY

SQL Query

SELECT "Person".name, count(*)
FROM "Person"
GROUP BY "Person".name
ORDER BY "Person".name

Cypher Query

MATCH (person:Person)
WHERE HAS (person.name)
RETURN person.name, count(*)
ORDER BY person.name

Order by is the same in both languages — ORDER BY expression ASC/DESC.

Written on October 12, 2014