The basic structure of a query is an ordered list of statements. The result of a query is a set of named record sets (one per statement).
<Query> ::= <Statements> <Statements> ::= <Statement> [; <Statements>]
A statement defines a record set by specifying:
<Statement> ::= (DEFINE | RETURN) <Key> AS <Select> [<From>] [<Where>] [<GroupBy>] [<Having>] [<OrderBy>] [<Page>]
A statement includes a list of assignments that compute the derived properties populated into the resulting records:
<Select> ::= SELECT <Assigns> <Assigns> ::= <Assign> [, <Assigns>] <Assign> ::= <Expr> AS <Key>
A statement’s input record set is either the result of a previous statement, the navigation state’s records (NavStateRecords), or the Dgraph’s base records (AllBaseRecords). The omission of the FROM clause implies FROM NavStateRecords.
<From> ::= FROM <Key> ::= FROM NavStateRecords ::= FROM AllBaseRecords
As in SQL, an optional WHERE clause represents a pre-filter on inbound records, and an optional HAVING clause represents a post-filter on the output records:
<Where> ::= WHERE <Filter> <Having> ::= HAVING <Filter>
Input records need to be mapped to output records for the purposes of populating derived values in the output records. The input records provide the values used in expressions and Where filters.