Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Thursday 29 February 2024

What is Where in Neo4j

In Neo4j's Cypher Query Language, the WHERE clause is used to filter query results based on specified conditions. It allows you to narrow down the data returned by a query by applying predicates to match only those elements that satisfy the given criteria.


Syntax:


MATCH (variable:Label)

WHERE condition

RETURN variable


Example:

Suppose we have a graph of Person nodes, each with a name and age property. We want to retrieve persons older than 30.


MATCH (p:Person)

WHERE p.age > 30

RETURN p.name, p.age


In this example:

- MATCH (p:Person) matches all nodes labeled as Person and assigns them to the variable p.

- WHERE p.age > 30 filters the matched nodes, selecting only those where the age property is greater than 30.

- RETURN p.name, p.age returns the name and age properties of the filtered nodes.


The WHERE clause supports various comparison operators (e.g., <, <=, >, >=, =, <>), logical operators (e.g., AND, OR, NOT), and functions for string manipulation, mathematical calculations, and more.


Additionally, you can combine multiple conditions using logical operators within the WHERE clause to create complex filtering conditions:


MATCH (p:Person)

WHERE p.age > 30 AND p.city = 'New York'

RETURN p.name, p.age, p.city


In this query, we're retrieving persons older than 30 who also live in New York.


The WHERE clause is a fundamental part of Cypher queries in Neo4j, allowing you to specify precisely the subset of data you're interested in retrieving or modifying.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.