``` ::= [WITH ] FROM { [] [ [AS] ] [ { JOIN | LEFT JOIN | RIGHT JOIN | OUTER JOIN [ALL] } [ [AS] ] ON ] } [ ,...n ] [ WHERE ] SELECT [ TOP ] [ DISTINCT ] { * | { { [] | }. ] * | [ [ AS ] column_alias ] | column_alias = expression } [ ,...n ] } [ GROUP BY { | } [ ,...n ] ] [ HAVING ] [ INTO ] [ ORDER BY { | } [ ,...n ] ] [ { UNION [ WITH DUPS ] | EXCEPT | INTERSECT | DIVIDED BY [ WITH REMAINDER ] | CROSS JOIN [ ( { { 1 | 2 }:{ * | 1..n } } ) ] } ] [ ...n ] ``` ``` ::= { [ NOT ] | ( ) } [ { { AND | OR } [ NOT ] { | ( ) } [ ...n ] ] ``` ``` ::= { expression expression | expression [ NOT ] BETWEEN expression AND expression | expression IS [ NOT ] NULL | expression IS [ NOT ] DISTINCT FROM expression | expression [ NOT ] IN ( { ) | expression [ ,...n ] } ) | expression { ALL | ANY} ( ) | EXISTS ( ) } ``` ``` ::= { constant | | | [ ] | } ``` ``` ::= { = | <> | != | > | >= | !> | < | <= | !< } ``` ``` ` ::= { [ { . | . } ] | | } ``` ``` ::= IF THEN ELSE ENDIF | CASE ` WHEN { | } THEN [ ...n ] [ ELSE ] END | COALESCE ( [ ,...n ] ) | native hoon (stretch goal) ``` 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 allowed in Common Table Experessions (CTE, WITH clause) or in any query joined by set operators except for the last of the queries. `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.