5.3 Complex Path Patterns
You can query a SQL property graph using complex path patterns.
Cyclic Path Patterns
Vertex and edge path patterns can form cycles. For instance, consider the following graph pattern:
MATCH (a IS person) -[IS friends]-> (a IS
                person)
The preceding graph pattern describes a single path pattern, and it contains the
                vertex variable a twice. Thus, this finds cycles in the graph such
                that a binds to a person that has a
                    friends edge to itself.
                  
Also, note the following:
- The label personfor the vertex variableaneed not be repeated twice. The result is the same with or without repeating the label expression.
- You can use multiple in-line WHEREclauses to add conditions on the same pattern variable.
- Using the same edge variable twice in a path pattern also has the semantics that the edges must be the same.
Cycles can be longer than a single edge. See Example 5-11.
Multiple Path Patterns
A MATCH clause may have more than one path pattern, in a
                comma-separated list. For instance, the following example shows two  path
                patterns:
                  
MATCH (a IS person WHERE a.name='John') -[IS student_of]-> (b IS university),
(a IS person WHERE a.name='John') -[IS friends]-> (c IS person)Any graph pattern variables in common between two path patterns denotes
                an overlap between the path patterns. In the preceding example, the vertex variable
                    a is shared. Note that the variable a must
                bind to the same graph element table in each element pattern of the graph pattern,
                and thus there is an implicit natural inner join on such repeated graph pattern
                variables.
                  
If there are no shared variables between the two path patterns, then the resulting output set is a cross product of the outputs of the individual path patterns. See Example 5-9 and Example 5-10.
Parent topic: SQL Graph Queries