11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.71 2003/11/01 01:56:29 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/select.sgml,v 1.72 2003/11/04 00:34:45 tgl Exp $
33PostgreSQL documentation
44-->
55
@@ -41,11 +41,6 @@ where <replaceable class="parameter">from_item</replaceable> can be one of:
4141 <replaceable class="parameter">from_item</replaceable> [ NATURAL ] <replaceable class="parameter">join_type</replaceable> <replaceable class="parameter">from_item</replaceable> [ ON <replaceable class="parameter">join_condition</replaceable> | USING ( <replaceable class="parameter">join_column</replaceable> [, ...] ) ]
4242</synopsis>
4343
44- <comment>FIXME: This last syntax is incorrect if the join type is an
45- INNER or OUTER join (in which case one of NATURAL, ON ..., or USING
46- ... is mandatory, not optional). What's the best way to fix
47- this?</comment>
48-
4944 </refsynopsisdiv>
5045
5146 <refsect1>
@@ -107,7 +102,7 @@ this?</comment>
107102
108103 <listitem>
109104 <para>
110- The actual output rows are computed the
105+ The actual output rows are computedusing the
111106 <command>SELECT</command> output expressions for each selected
112107 row. (See
113108 <xref linkend="sql-select-list" endterm="sql-select-list-title">
@@ -125,15 +120,6 @@ this?</comment>
125120 </para>
126121 </listitem>
127122
128- <listitem>
129- <para>
130- If the <literal>LIMIT</literal> or <literal>OFFSET</literal>
131- clause is specified, the <command>SELECT</command> statement
132- only returns a subset of the result rows. (See <xref
133- linkend="sql-limit" endterm="sql-limit-title"> below.)
134- </para>
135- </listitem>
136-
137123 <listitem>
138124 <para>
139125 <literal>DISTINCT</literal> eliminates duplicate rows from the
@@ -145,6 +131,15 @@ this?</comment>
145131 </para>
146132 </listitem>
147133
134+ <listitem>
135+ <para>
136+ If the <literal>LIMIT</literal> or <literal>OFFSET</literal>
137+ clause is specified, the <command>SELECT</command> statement
138+ only returns a subset of the result rows. (See <xref
139+ linkend="sql-limit" endterm="sql-limit-title"> below.)
140+ </para>
141+ </listitem>
142+
148143 <listitem>
149144 <para>
150145 The <literal>FOR UPDATE</literal> clause causes the
@@ -291,17 +286,21 @@ this?</comment>
291286 </para>
292287
293288 <para>
294- A <literal>JOIN</literal> clause, combines two
295- <literal>FROM</> items. (Use parentheses if necessary to
296- determine the order of nesting.)
289+ A <literal>JOIN</literal> clause combines two
290+ <literal>FROM</> items. Use parentheses if necessary to
291+ determine the order of nesting. In the absence of parentheses,
292+ <literal>JOIN</literal>s nest left-to-right. In any case
293+ <literal>JOIN</literal> binds more tightly than the commas
294+ separating <literal>FROM</> items.
297295 </para>
298296
299297 <para>
300298 <literal>CROSS JOIN</> and <literal>INNER JOIN</literal>
301- produce a simple Cartesian product, the same as you get from
302- listing the two items at the top level of <literal>FROM</>.
299+ produce a simple Cartesian product, the same result as you get from
300+ listing the two items at the top level of <literal>FROM</>,
301+ but restricted by the join condition (if any).
303302 <literal>CROSS JOIN</> is equivalent to <literal>INNER JOIN ON
304- (true )</>, that is, no rows are removed by qualification.
303+ (TRUE )</>, that is, no rows are removed by qualification.
305304 These join types are just a notational convenience, since they
306305 do nothing you couldn't do with plain <literal>FROM</> and
307306 <literal>WHERE</>.
@@ -315,7 +314,7 @@ this?</comment>
315314 condition. This left-hand row is extended to the full width
316315 of the joined table by inserting null values for the
317316 right-hand columns. Note that only the <literal>JOIN</>
318- clauses own condition is considered while deciding which rows
317+ clause's own condition is considered while deciding which rows
319318 have matches. Outer conditions are applied afterwards.
320319 </para>
321320
@@ -410,7 +409,7 @@ GROUP BY <replaceable class="parameter">expression</replaceable> [, ...]
410409 expressions. <replaceable
411410 class="parameter">expression</replaceable> can be an input column
412411 name, or the name or ordinal number of an output column
413- (<command>SELECT</command> list), or it can be an arbitrary
412+ (<command>SELECT</command> list item ), or an arbitrary
414413 expression formed from input-column values. In case of ambiguity,
415414 a <literal>GROUP BY</literal> name will be interpreted as an
416415 input-column name rather than an output column name.
@@ -497,7 +496,7 @@ HAVING <replaceable class="parameter">condition</replaceable>
497496
498497 <para>
499498 Currently, <literal>FOR UPDATE</> may not be specified either for
500- a <literal>UNION</> result or forthe inputs of <literal>UNION</>.
499+ a <literal>UNION</> result or forany input of a <literal>UNION</>.
501500 </para>
502501 </refsect2>
503502
@@ -613,7 +612,7 @@ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC |
613612</synopsis>
614613 <replaceable class="parameter">expression</replaceable> can be the
615614 name or ordinal number of an output column
616- (<command>SELECT</command> list), or it can be an arbitrary
615+ (<command>SELECT</command> list item ), or it can be an arbitrary
617616 expression formed from input-column values.
618617 </para>
619618
@@ -623,7 +622,7 @@ ORDER BY <replaceable class="parameter">expression</replaceable> [ ASC | DESC |
623622 equal according to the leftmost expression, the are compared
624623 according to the next expression and so on. If they are equal
625624 according to all specified expressions, they are returned in
626- random order.
625+ an implementation-dependent order.
627626 </para>
628627
629628 <para>
@@ -660,7 +659,7 @@ SELECT name FROM distributors ORDER BY code;
660659
661660 <para>
662661 Optionally one may add the key word <literal>ASC</> (ascending) or
663- <literal>DESC</> (descending) aftereach expression in the
662+ <literal>DESC</> (descending) afterany expression in the
664663 <literal>ORDER BY</> clause. If not specified, <literal>ASC</> is
665664 assumed by default. Alternatively, a specific ordering operator
666665 name may be specified in the <literal>USING</> clause.
@@ -689,15 +688,18 @@ SELECT name FROM distributors ORDER BY code;
689688
690689 <para>
691690 The <literal>LIMIT</literal> clause consists of two independent
692- clauses:
691+ sub- clauses:
693692<synopsis>
694693LIMIT { <replaceable class="parameter">count</replaceable> | ALL }
695694OFFSET <replaceable class="parameter">start</replaceable>
696695</synopsis>
697696 <replaceable class="parameter">count</replaceable> specifies the
698- maximum number of rows to return,and <replaceable
697+ maximum number of rows to return,while <replaceable
699698 class="parameter">start</replaceable> specifies the number of rows
700- to skip before starting to return rows.
699+ to skip before starting to return rows. When both are specified,
700+ <replaceable class="parameter">start</replaceable> rows are skipped
701+ before starting to count the <replaceable
702+ class="parameter">count</replaceable> rows to be returned.
701703 </para>
702704
703705 <para>
@@ -754,6 +756,13 @@ SELECT DISTINCT ON (location) location, time, report
754756 of time values for each location, we'd have gotten a report from
755757 an unpredictable time for each location.
756758 </para>
759+
760+ <para>
761+ The <literal>DISTINCT ON</> expression(s) must match the leftmost
762+ <literal>ORDER BY</> expression(s). The <literal>ORDER BY</> clause
763+ will normally contain additional expression(s) that determine the
764+ desired precedence of rows within each <literal>DISTINCT ON</> group.
765+ </para>
757766 </refsect2>
758767
759768 <refsect2 id="SQL-FOR-UPDATE">
@@ -889,10 +898,10 @@ SELECT * FROM distributors ORDER BY 2;
889898 </para>
890899
891900 <para>
892- This example shows how to obtain the union of the tables
901+ The next example shows how to obtain the union of the tables
893902 <literal>distributors</literal> and
894903 <literal>actors</literal>, restricting the results to those that begin
895- with letter W in each table. Only distinct rows are wanted, so the
904+ withthe letter W in each table. Only distinct rows are wanted, so the
896905 key word <literal>ALL</literal> is omitted.
897906
898907<programlisting>
@@ -925,7 +934,7 @@ SELECT actors.name
925934
926935 <para>
927936 This example shows how to use a function in the <literal>FROM</>
928- clause, both with and without a column definition list.
937+ clause, both with and without a column definition list:
929938
930939<programlisting>
931940CREATE FUNCTION distributors(int) RETURNS SETOF distributors AS '
@@ -1048,7 +1057,8 @@ SELECT distributors.* FROM distributors d, distributors distributors;
10481057 </para>
10491058
10501059 <para>
1051- SQL99 uses a slightly different definition which is not upward compatible
1060+ SQL99 uses a slightly different definition which is not entirely upward
1061+ compatible
10521062 with SQL92. In most cases, however, <productname>PostgreSQL</productname>
10531063 will interpret an <literal>ORDER BY</literal> or <literal>GROUP
10541064 BY</literal> expression the same way SQL99 does.