GQL overview Stay organized with collections Save and categorize content based on your preferences.
Graph Query Language (GQL) is a language designed to query graph data. This pagedescribes the high level structure of GQL.
Statement and clause
In GQL, a statement refers to a complete unit of execution, and a clauserepresents a modifier to statements. See thestatement list for a complete list.
Working table
A working table refers to the intermediate table representing the input oroutput of a GQL statement.
A GQL statement receives an incoming working table and produces an outgoingworking table.
The first incoming working table is a table with a single row. The lastoutgoing working table is returned as the query results.
Linear query statement
A linear query statement consists of multiple statements from thestatementlist. It always ends with aRETURN statement.
Each statement generates intermediate results (the working table) andthen passes those results to the next statement. The output of alinear query statement comes from the finalRETURN statement.
Examples
GRAPHFinGraphMATCH(p:Person)-[o:Owns]->(a:Account)FILTERp.birthday <'1990-01-10'RETURNp.name/*------+ | name | +------+ | Dana | | Lee | +------*/Combining linear query statements with set operators
You can use a set operator to combine multiple linear query statements into one.For more information, see the syntax for theGQL set operation.
Examples
A set operator between two linear query statements with the same set of outputcolumn names and types but with different column orders is supported. For example:
GRAPHFinGraphMATCH(p:Person)RETURNp.name,1ASgroup_idUNIONALLMATCH(p:Person)RETURN2ASgroup_id,p.name/*------+----------+ | name | group_id | +------+----------+ | Alex | 1 | | Dana | 1 | | Lee | 1 | | Alex | 2 | | Dana | 2 | | Lee | 2 | +------+----------*/Chaining linear query statements with theNEXT statement
You can use theNEXT keyword to chain multiple linear query statementsinto one.
The final linear query statement must produce non-GQL data types, butlinear query statements that proceed it can produce GQL data types,such as nodes and edges.
Examples
The following is an example of a graph query chaining multiple linear query statementsusingNEXT.
GRAPHFinGraphMATCH(a:Account{is_blocked:TRUE})RETURNaUNIONALLMATCH(a:Account)<-[:Owns]-(p:Person{id:2})RETURNaNEXTMATCH(a:Account)-[t:Transfers]->(oa:Account)WITHDISTINCToaRETURNoa.nick_name/*----------------+ | nick_name | +----------------+ | Vacation Fund | | Vacation Fund | | Rainy Day Fund | +----------------*/Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.