UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Questioned Paths
    • Shortest Paths
    • Cheapest Paths
    • K-Hop Traversal
    • Graph Patterns
    • Overview
    • Open Graphs
    • Closed Graphs
    • Graph Types
    • Constraints
    • Projections
    • Storage Maintenance
    • Node and Edge IDs
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • MERGE
    • SET
    • REMOVE
    • DELETE
    • FOREACH
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Element Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Null Functions
    • Utility Functions
    • Type Conversion Functions
    • Table Functions
    • Database Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Expressions
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Execution Plan
  • Backup and Restore
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Naming Conventions
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Querying

Query Composition

A GQL query is composed of multiple statements. Each statement is a unit that can be executed by the database. A typical GQL query begins with a MATCH statement to retrieve data from the graph, and ends with a RETURN statement to output results to the client.

A clause is a component of a statement that performs a specific function, such as WHERE for filtering. A clause on its own is not a complete instruction, but must be part of a statement.

GQL supports the following statement for querying the database:

StatementDescriptionSupported Clauses
MATCHRetrieves nodes, edges, and paths from the graph using patterns.WHERE, YIELD
OPTIONAL MATCHSame as MATCH, but returns null instead of empty results when no match is found.WHERE
FILTERDiscards records in the intermediate result table that do not satisfy the specified conditions.
LETDefines variables and adds corresponding columns to the intermediate result table.
FORUnnests a list into individual rows.
ORDER BYSorts records in the intermediate result or output table.
LIMITRestricts the number of records to be retained in the intermediate result or output table.
SKIPDiscards a specified number of records from the beginning of the intermediate result or output table.
CALLInvokes an inline procedure or named procedure.YIELD
RETURNSpecifies the columns to include in the output table.GROUP BY [HAVING]

Linear Query

A linear query executes sequentially, where each statement is processed one after another without any branching or conditional logic. The result is returned in a straightforward progression.

Every linear query must conclude with a RETURN statement. Optional result modifiers — ORDER BY, SKIP, and LIMIT — can follow RETURN in any order and combination.

For example, this is a linear query where the MATCH, FILTER and RETURN statements processed in a linear order:

GQL
MATCH (:User {_id: "U01"})-[:Follows]->(u:User)
FILTER u.city = "New York"
RETURN u

Composite Query

A composite query combines the result sets of multiple linear queries with query conjunctions (UNION, EXCEPT, INTERSECT, and OTHERWISE).

For example, this is a composite query that uses UNION ALL to combine the result sets of two linear queries:

GQL
MATCH (n:Club) RETURN n
UNION
MATCH (n:User) RETURN n

Learn more about composite query →

Advanced Linear Composition with NEXT

The NEXT statement chains multiple linear or composite query statements, enabling more complex queries.

Learn more about NEXT →