You are viewing the documentation for a prerelease version.

View Latest

SELECT Syntax

This page enables you to drill down through the syntax of a SELECT query.
with-select ::= [ with-clause ] select
with select
select-term ::= subselect | '(' select ')'
select term
subselect ::= select-from | from-select
subselect
set-op ::= UNION | INTERSECT | EXCEPT
set op

WITH Clause

with-clause ::= WITH alias AS '(' ( select | expression ) ')' [ ',' alias AS '(' ( select | expression ) ')' ]*
with clause

SELECT Clause

select-clause ::= SELECT [ ALL | DISTINCT ] ( result-expr [ , result-expr ]* | ( RAW | ELEMENT | VALUE ) expr [ [ AS ] alias ] )
select clause

FROM Clause

from-clause ::= FROM from-term
from clause
from-keyspace ::= keyspace-ref [ [ AS ] alias ] [ use-clause ]
from keyspace
keyspace-ref ::= [ namespace ':' ] keyspace
from keyspace ref
namespace ::= identifier
namespace
keyspace ::= identifier
keyspace
from-subquery ::= subquery-expr [ AS ] alias
select expr
subquery-expr ::= '(' select ')'
subquery expr
from-generic ::= expr [ AS alias ]
generic expr

JOIN Clause

join clause

ANSI JOIN

ansi-join-type? 'JOIN' ansi-join-rhs ansi-join-hints? ansi-join-predicate
ansi-join-type ::= INNER | ( LEFT [ OUTER ] ) | ( RIGHT [ OUTER ] )
ansi join type
ansi-join-rhs ::= rhs-keyspace | rhs-subquery | rhs-generic
rhs-keyspace | rhs-subquery | rhs-generic
rhs-keyspace ::= keyspace-ref [ [ AS ] alias ]
keyspace-ref ( 'AS'? alias )?
rhs-subquery ::= subquery-expr [ AS ] alias
subquery-expr 'AS'? alias
rhs-generic ::= expr [ AS alias ]
expr 'AS'? alias
ansi-join-hints ::= use-hash-hint | use-nl-hint | multiple-hints
ansi use clause
use-hash-hint ::= USE use-hash-term
use hash hint
use-hash-term ::= HASH '(' ( BUILD | PROBE ) ')'
use hash predicate
use-nl-hint ::= USE use-nl-term
use nl hint
use-nl-term ::= NL
use nl predicate
ansi-hint-terms ::= use-hash-term | use-nl-term
ansi hint predicates
other-hint-terms ::= use-index-term | use-keys-term
other hint predicates
ansi-join-predicate ::= ON expr
ansi join predicate

Lookup JOIN

lookup-join-clause ::= [ lookup-join-type ] JOIN lookup-join-rhs lookup-join-predicate
lookup-join-type? 'JOIN' lookup-join-rhs lookup-join-predicate
lookup-join-type ::= INNER | ( LEFT [ OUTER ] )
lookup join type
lookup-join-rhs ::= keyspace-ref [ [ AS ] alias ]
keyspace-ref ( 'AS'? alias )?
lookup-join-predicate ::= ON [ PRIMARY ] KEYS expr
lookup join predicate

Index JOIN

index-join-clause ::= [ index-join-type ] JOIN index-join-rhs index-join-predicate
index-join-type? 'JOIN' index-join-rhs index-join-predicate
index-join-type ::= INNER | ( LEFT [ OUTER ] )
index join type
index-join-rhs ::= keyspace-ref [ [ AS ] alias ]
keyspace-ref ( 'AS'? alias )?
index-join-predicate ::= ON [ PRIMARY ] KEY expr FOR alias
index join predicate

NEST Clause

nest clause

ANSI NEST

ansi-nest-clause ::= [ ansi-nest-type ] NEST ansi-nest-rhs ansi-nest-predicate
ansi-nest-type? 'NEST' ansi-nest-rhs ansi-nest-predicate
ansi-nest-type ::= INNER | ( LEFT [ OUTER ] )
ansi nest type
ansi-nest-rhs ::= keyspace-ref [ [ AS ] alias ]
keyspace-ref ( 'AS'? alias )?
ansi-nest-predicate ::= ON expr
ansi nest predicate

Lookup NEST

lookup-nest-clause ::= [ lookup-nest-type ] NEST lookup-nest-rhs lookup-nest-predicate
lookup-nest-type? 'NEST' lookup-nest-rhs lookup-nest-predicate
lookup-nest-type ::= INNER | ( LEFT [ OUTER ] )
lookup nest type
lookup-nest-rhs ::= keyspace-ref [ [ AS ] alias ]
keyspace-ref ( 'AS'? alias )?
lookup-nest-predicate ::= ON KEYS expr
lookup nest predicate

Index NEST

index-nest-clause ::= [ index-nest-type ] NEST index-nest-rhs index-nest-predicate
index-nest-type? 'NEST' index-nest-rhs index-nest-predicate
index-nest-type ::= INNER | ( LEFT [ OUTER ] )
index nest type
index-nest-rhs ::= keyspace-ref [ [ AS ] alias ]
keyspace-ref ( 'AS'? alias )?
index-nest-predicate ::= ON KEY expr FOR alias
index nest predicate

UNNEST Clause

unnest-clause ::= from-term [ unnest-type ] ( UNNEST | FLATTEN ) expr [ [ AS ] alias ]
unnest clause
unnest-type ::= INNER | ( LEFT [ OUTER ] )
unnest type

USE Clause

use clause
use-keys-clause ::= USE use-keys-term
use keys clause
use-keys-term ::= [ PRIMARY ] KEYS expr
use keys predicate
use-index-clause ::= USE use-index-term
use index clause
use-index-term ::= INDEX '(' index-ref [ ',' index-ref ]* ')'
use index predicate
index-ref ::= index-name [ index-using ]
index ref
index-name ::= identifier
index name
index-using ::= USING ( VIEW | GSI | FTS )
index using

LET Clause

let-clause ::= LET alias '=' expr [ ',' alias '=' expr ]*
let clause

WHERE Clause

where-clause ::= WHERE cond
where clause
cond ::= expr
cond

GROUP BY Clause

group-by-clause ::= GROUP BY expr [ ',' expr ]* [ letting-clause ] [ having-clause ] | letting-clause
group by clause
letting-clause ::= LETTING alias '=' expr [ ',' alias '=' expr ]*
letting clause
having-clause ::= HAVING cond
having clause

ORDER BY Clause

order-by-clause ::= ORDER BY ordering-term [ ',' ordering-term ]*
order by clause
ordering-term::= expr [ ASC | DESC ] [ NULLS ( FIRST | LAST ) ]
ordering term

LIMIT Clause

limit-clause ::= LIMIT expr
limit clause

OFFSET Clause

offset-clause ::= OFFSET expr
offset clause