``` ::= [WITH () AS [ ,...n ] ] FROM [ ] [ [AS] ] [ { { JOIN | LEFT JOIN | RIGHT JOIN | OUTER JOIN [ALL] } [ ] [ [AS] ] ON } [ ...n ] | CROSS JOIN ] [ { SCALAR [ AS ] } [ ...n ] ] [ WHERE ] SELECT [ TOP ] [ BOTTOM ] [ DISTINCT ] { * | { { [] | }.* | { | } [ [ AS ] ] | } [ ,...n ] } [ GROUP BY { | } [ ,...n ] [ HAVING ] [ AGGREGATE [ [ AS ] { [^..^] | [^..^] | } ] { | (TBD) *hoon } ] ] [ INTO ] [ ORDER BY { | } [ ASC | DESC ] [ ,...n ] ] [ { UNION | COMBINE | EXCEPT | INTERSECT | DIVIDED BY [ WITH REMAINDER ] ``` ``` ::= { [ NOT ] | ( ) } [ { { AND | OR } [ NOT ] { | ( ) } [ ...n ] ] ``` ``` ::= { expression expression | expression [ NOT ] BETWEEN expression [ AND ] expression | expression IS [ NOT ] DISTINCT FROM expression | expression [ NOT ] IN { | ( ,...n ) } | expression { ALL | ANY} ( ) | [ NOT ] EXISTS { | } } ``` ``` ::= IF THEN { | } ELSE { | } ENDIF | CASE WHEN { | } THEN { | } [ ...n ] [ ELSE { | } ] END | COALESCE ( [ ,...n ] ) | BEGIN END | *hoon (TBD) ``` ``` ::= { constant | | } ``` ``` ::= { = | <> | != | > | >= | !> | < | <= | !< } ``` ``` ::= [ [ ] | } ]. ``` ``` ` ::= { [ { . | . } ] | | } ``` Discussion: Not shown in diagrams, parentheses distinguish order of operations for binary conjunctions `AND` and `OR`. Set operators apply the previous result set to the next query unless otherwise qualified by parentheses. `ORDER BY` is not recommended in Common Table Experessions (CTE, WITH clause) or in any query joined by set operators prior to the last of the queries, except when `TOP` or `BOTTOM` is specified. `SELECT INTO` targets an existing table not otherwise in the query. `COALESCE` returns the first `` in the list that does not evaluate to `~` (in the case of unit) or not in the selected `` due to `LEFT` or `RIGHT JOIN`. If a `CASE WHEN` expression is a ``, the expected boolean (or loobean) logic applies. If it is a atom value 0 is treated as false and any other value as true (not loobean). Cross database joins are allowed, but not cross ship joins. `DISTINCT FROM` is like equals, `=`, except comparing two nulls will yield false.