Previous Topic: SELECTNext Topic: Full-Select Statement


Subselect

►►─ SELECT ─┬────────────────┬────────────────────────────────────────────────►
            └─┬─ ALL ◄ ────┬─┘
              └─ DISTINCT ─┘

 ►─┬─ * ────────────────────────────────────────────┬─ FROM ──────────────────►
   │ ┌─ , ────────────────────────────────────────┐ │
   └─▼─┬─ expression ─┬───────────────────────┬─┬─┴─┘
       │              └┬────┬ sql-identifier ─┘ │
       │               └ AS ┘                   │
       └─┬─ table-name.* ───────┬───────────────┘
         ├─ view-name.* ────────┤
         └─ correlation-name.* ─┘

   ┌─ , ─────────┐
 ►─▼─┤table-ref├─┴─┬──────────────────────────┬───────────────────────────────►
                   └─ WHERE search-condition ─┘

 ►─┬──────────────────────────────┬─┬───────────────────────────┬─────────────►◄
   │            ┌─ , ───────────┐ │ └─ HAVING search-condition ─┘
   └─ GROUP BY ─▼─ column-name ─┴─┘

Expansion of table-ref

├──┬─┬─ table-name ─┬─┬──────┬─┬────────────────────┬─┬────────────────────────┤
   │ └─ view-name ──┘ └─ AS ─┘ └─ correlation-name ─┘ │
   └─┤alternate-join-type├────────────────────────────┘

Expansion of alternate-join-type

├──┬─────┬─ table-ref ─┬─ INNER ────────────┬─────────────────────────────────►
   └─ ( ─┘             └─ LEFT ─┬─────────┬─┘
                                └─ OUTER ─┘

 ►─ JOIN ─ table-ref ─┬───────────────┬─┬─────┬────────────────────────────────┤
                      └─ ON ─ s-cond ─┘ └─ ) ─┘

The s-cond (search-condition) in this optional ON clause differs from the one in the WHERE clause in that the ON clause defines the join conditions that determine which rows contain nulls, as opposed to the WHERE clause, which eliminates rows from the result entirely. Also, if you use the optional parentheses, they must be balanced, that is, if you use an open parenthesis, you must also use a close parenthesis.