Query Language Snippets

All Snippets
SQL Read
Use CASE for conditional logic in queries.
SELECT name,
  CASE
    WHEN salary > 50000 THEN 'High'
    WHEN salary > 30000 THEN 'Medium'
    ELSE 'Low'
  END as salary_level
FROM employees;
Cypher Read
Find all nodes with a specific label.
MATCH (p:Person) RETURN p;
Cypher Read
Find nodes with a specific property.
MATCH (p:Person {name: 'Alice'}) RETURN p;
Cypher Read
Find friends of a person.
MATCH (a:Person {name: 'Alice'})-[:FRIEND]->(friends)
RETURN friends.name;
Cypher Read
Count relationships of a type.
MATCH (n)-[r:FRIEND]->()
RETURN count(r);
Cypher Read
Find the shortest path between two nodes.
MATCH p = shortestPath((a:Person)-[*..5]-(b:Person))
WHERE a.name = 'Alice' AND b.name = 'Bob'
RETURN p;
Cypher Read
Use WHERE to filter nodes and relationships.
MATCH (a:Person)-[r:FRIEND]->(b:Person)
WHERE a.age > 30
RETURN a.name, b.name;
Cypher Read
Use aggregations (COUNT, SUM, AVG, etc.).
MATCH (p:Person)
RETURN p.department, COUNT(*), AVG(p.age);
Cypher Read
Use variable-length relationships.
MATCH (a:Person)-[:FRIEND*1..3]->(b:Person)
RETURN a.name, b.name;
Cypher Read
Use parameters in queries for safety and reusability.
MATCH (p:Person {name: $name})
RETURN p;
GraphQL Read
Basic query to fetch user data.
query {
  user(id: 1) {
    id
    name
    email
  }
}
GraphQL Read
Query with variables for dynamic input.
query GetUser($userId: Int!) {
  user(id: $userId) {
    name
    email
  }
}