Documentation Source Text

Check-in [4c5d78209a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Additional clarification on syntax restrictions in SELECT statements.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4c5d78209a5b03a04c805cca2db21d50bcf265e3
User & Date: drh 2014-01-30 15:32:07.112
Context
2014-01-30
15:56
Update the mmap documentation to describe the problem of Windows not truncating memory mapped files. (check-in: fa77748670 user: drh tags: trunk)
15:32
Additional clarification on syntax restrictions in SELECT statements. (check-in: 4c5d78209a user: drh tags: trunk)
15:03
Further enhancements to the SELECT documentation. (check-in: 979599b0b6 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to pages/lang.in.
3617
3618
3619
3620
3621
3622
3623
3624
3625

3626
3627
3628
3629




3630
3631
3632
3633
3634
3635
3636
3637
any changes to the database.

<p>The "[select-stmt]" syntax diagram above attempts to show as much of the
SELECT statement syntax as possible in a single diagram, as some readers
find that helpful.  Alternative syntax diagrams that break the syntax down
into smaller chunks are shown elsewhere in this document.

<p>Note that there are paths through the syntax diagrams for SELECT that
are not allowed in practice.  For example, an [ORDER BY] or [LIMIT] clause

can only occur on the right-most SELECT of a [compound select], even though
the [select-stmt] syntax diagram shows that they can occur anywhere. 
And, a [VALUES] clause may not immediately follow a [WITH] clause in
a [simple SELECT] even though the [extended-simple-select-stmt] diagram




shows that it can.  Restrictions such as these are described in the text.

<p>The SELECT statement is the most complicated command in the SQL language.
To make the description easier to follow, some of the passages below describe
the way the data returned by a SELECT statement is determined as a series of
steps. It is important to keep in mind that this is purely illustrative -
in practice neither SQLite nor any other SQL engine is required to follow 
this or any other specific process.







|
|
>
|
|
|
|
>
>
>
>
|







3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
any changes to the database.

<p>The "[select-stmt]" syntax diagram above attempts to show as much of the
SELECT statement syntax as possible in a single diagram, as some readers
find that helpful.  Alternative syntax diagrams that break the syntax down
into smaller chunks are shown elsewhere in this document.

<p>Note that there are paths through the syntax diagrams that
are not allowed in practice.  Some example:
<ul>
<li>An [ORDER BY] or [LIMIT] clause can only occur on the right-most 
    SELECT of a [compound select].
<li>A [VALUES] clause can be the first element in a [compound SELECT]
    that uses a [WITH] clause, but a [simple SELECT] that consists of
    just a [VALUES] clause cannot be preceded by a [WITH] clause.
<li>The [WITH] clause must occur on the first SELECT of a [compound SELECT].
    It cannot follow a [compound-operator].
</ul>
These and other similar syntax restrictions are described in the text.

<p>The SELECT statement is the most complicated command in the SQL language.
To make the description easier to follow, some of the passages below describe
the way the data returned by a SELECT statement is determined as a series of
steps. It is important to keep in mind that this is purely illustrative -
in practice neither SQLite nor any other SQL engine is required to follow 
this or any other specific process.
4099
4100
4101
4102
4103
4104
4105
4106


4107
4108
4109
4110
4111
4112
4113
</ul>


<h3>The WITH Clause</h3>

<p>SELECT statements may be optional preceded by a single
[WITH clause] that defines one or more [common table expressions]
for using within the SELECT statement.



<tcl>
##############################################################################
Section UPDATE update {UPDATE *UPDATEs}

RecursiveBubbleDiagram update-stmt
</tcl>







|
>
>







4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
</ul>


<h3>The WITH Clause</h3>

<p>SELECT statements may be optional preceded by a single
[WITH clause] that defines one or more [common table expressions]
for use within the SELECT statement.  Contrary to what the
[select-stmt] syntax diagram shows, a [WITH clause] cannot occur
after a [compound-operator].

<tcl>
##############################################################################
Section UPDATE update {UPDATE *UPDATEs}

RecursiveBubbleDiagram update-stmt
</tcl>