When multiple path patterns are supplied in a comma-separated list, GQL evaluates them and combines the results:
1. Connected Paths (Equi-Joins)
If the path patterns share one or more variables, the query engine performs an equi-join on those variables, returning only records where the bound elements are identical.
Find wizards who are common knows-connections of "Albus" and "Draco" and also teach a spell:
MATCH ({name: "Albus"})-[:Knows]->(u:Wizard)<-[:Knows]-({name: "Draco"}),
(u)-[:Teaches]->(s:Spell)
RETURN u.name AS common_friend, s.name AS spell
Here, the variable u is declared in both path patterns. GQL joins the records on u.
2. Disconnected Paths (Cartesian Product)
If the path patterns share no common variables, the query engine performs a Cartesian product, pairing every record from the first match with every record from the second.
MATCH (w1:Wizard {affinity: "Light"}), (w2:Wizard {affinity: "Dark"})
RETURN w1.name, w2.name
Warning: Cartesian products can generate large result sets and increase query execution times. Avoid disconnected path patterns unless explicitly necessary.