diff --git a/docs-2.0/3.ngql-guide/4.variable-and-composite-queries/2.user-defined-variables.md b/docs-2.0/3.ngql-guide/4.variable-and-composite-queries/2.user-defined-variables.md index aeef106bf1f..5f3fb87e786 100644 --- a/docs-2.0/3.ngql-guide/4.variable-and-composite-queries/2.user-defined-variables.md +++ b/docs-2.0/3.ngql-guide/4.variable-and-composite-queries/2.user-defined-variables.md @@ -48,3 +48,18 @@ nebula> $var = GO FROM "player100" OVER follow YIELD dst(edge) AS id; \ | "Spurs" | "Manu Ginobili" | +-----------+-----------------+ ``` + +## Set operations and scope of user-defined variables + +When assigning variables within a compound statement involving set operations, it is important to enclose the scope of the variable assignment in parentheses. In the example below, the source of the `$var` assignment is the results of the output of two `INTERSECT` statements. + +```ngql +$var = ( \ + GO FROM "player100" OVER follow \ + YIELD dst(edge) AS id \ + INTERSECT \ + GO FROM "player100" OVER follow \ + YIELD dst(edge) AS id \ + ); \ + GO FROM $var.id OVER follow YIELD follow.degree AS degree +``` \ No newline at end of file