Optional match - many clauses

Hi,

Simple questions
NEO 3.4.14

What is difference between:
1.
MATCH a
OPTIONAL MATCH a->b
OPTIONAL MATCH b->c
OPTIONAL MATCH b->d
RETURN a,b,c,d

MATCH a
OPTIONAL MATCH a->b, b->c, b->d
RETURN a,b,c,d

I see difference in result in case a->d returns null.

The first version returns a,b,c
The second version returns a.

Best,
Cezary

The OPTIONAL MATCH considers the entire pattern, or all subpatterns as a whole, in the case of your second query. So in your second query if 2 of the subpatterns are present but the 3rd (b->d) is not, then the entire pattern was not found, and you'll get nulls for all the new variables.

In contrast, your first approach considers each of the patterns separately, so the optional matching of one is not dependent upon the optional matching of another (excepting that the last two optional matches are dependent on b from the first optional match).

Thanks :slightly_smiling_face:

I expected this but hoped that there is diff:

OPTIONAL MATCH a->b->c
OPTIONAL MATCH a->b, b->c