Return Two value in one query

Hi,
In the following query
MATCH (a:A) WHERE ID(a) = 10 AND a.validTo IS NULL MATCH (a)-[r:Relation]->(b:B) WHERE r.validTo IS NULL AND b.validTo IS NULL RETURN a,b

If the second MATCH clause matches nothing, the first MATCH clause will not return the a. So Is it a way for having the value of a, even if the will be no match for b, using only one query?

If you want to return a regardless of whether the specified traversal can be completed, you should use the OPTIONAL MATCH clause:

 MATCH (a:A) WHERE ID(a) = 10 AND a.validTo IS NULL OPTIONAL MATCH (a)-[r:Relation]->(b:B) WHERE r.validTo IS NULL AND b.validTo IS NULL RETURN a,b

On patterns that match completely, both elements will be returned, and on failed traversals, a will be returned with a NULL value for b.

2 Likes

Hi jeffreylovitz,
Thanks for your answer.

Using the OPTIONAL MATCH I got the error

(error) RedisGraph does not support OPTIONAL MATCH

Iā€™m using the latest docker.
So in what version RedisGraph supports the OPTIONAL MATCH queries?

Using version 2.2.0 it started to work
Thanks

1 Like