WHERE clause¶
The WHERE clause declares one or more filter conditions in the form of boolean value expressions. It usually references one or more properties of a node or edge and filters the results produced by a preceding graph pattern matching clause or statement.
Syntax¶
- where_clause
where_clause ::=
'WHERE' value_expression
Parameters¶
value_expression¶
A boolean value expression that functions as a filter condition. Results that do not satisfy the condition are pruned.
For more information, see Boolean type and Expressions.
Examples¶
The following examples assume that the temporary graph #movie_temporary_graph has been created and data has been imported into it.
Filter with one condition¶
'''
USE #movie_temporary_graph {
TABLE result_table TYPED TABLE {movie STRING, audience INT64, rate DOUBLE}
MATCH (v@Movie)<-[e@Watch]-(u@`User`)
WHERE e.rate > 3
PER PATH {
EXPORT v.name AS movie, u.id AS audience, e.rate AS rate INTO result_table
}
FOR r IN result_table
RETURN r.movie AS movie, r.audience AS audience, r.rate AS rate
ORDER BY r.movie ASC, r.audience ASC, r.rate DESC
LIMIT 3
}
'''
Return:
+---------------+----------+------+
| movie | audience | rate |
+---------------+----------+------+
| A Close Shave | 16 | 4.0 |
| A Close Shave | 18 | 4.0 |
| A Close Shave | 19 | 4.0 |
+---------------+----------+------+
Filter with multiple conditions¶
'''
USE #movie_temporary_graph {
TABLE result_table TYPED TABLE {movie STRING, rate DOUBLE}
MATCH (v@Movie)<-[e@Watch]-(u@`User`)
WHERE e.rate > 2 AND u.id = 100
PER PATH {
EXPORT v.name AS movie, e.rate AS rate INTO result_table
}
FOR r IN result_table
RETURN r.movie AS movie, r.rate AS rate
}
'''
Return:
+--------------------------------------+------+
| movie | rate |
+--------------------------------------+------+
| Pi | 4.5 |
| William Shakespeare's Romeo & Juliet | 4.0 |
+--------------------------------------+------+