diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml index 6755ae5bda..3bc08e09ec 100644 --- a/doc/src/sgml/ref/select.sgml +++ b/doc/src/sgml/ref/select.sgml @@ -1,5 +1,5 @@ @@ -695,6 +695,45 @@ SELECT name FROM distributors ORDER BY code; was initialized. + + + <literal>DISTINCT</literal> Clause + + + If DISTINCT is specified, all duplicate rows are + removed from the result set (one row is kept from each group of + duplicates). ALL specifies the opposite: all rows are + kept; that is the default. + + + + DISTINCT ON ( expression [, ...] ) + keeps only the first row of each set of rows where the given + expressions evaluate to equal. The DISTINCT ON + expressions are interpreted using the same rules as for + ORDER BY (see above). Note that the first + row of each set is unpredictable unless ORDER + BY is used to ensure that the desired row appears first. For + example, + +SELECT DISTINCT ON (location) location, time, report + FROM weather_reports + ORDER BY location, time DESC; + + retrieves the most recent weather report for each location. But + if we had not used ORDER BY to force descending order + of time values for each location, we'd have gotten a report from + an unpredictable time for each location. + + + + The DISTINCT ON expression(s) must match the leftmost + ORDER BY expression(s). The ORDER BY clause + will normally contain additional expression(s) that determine the + desired precedence of rows within each DISTINCT ON group. + + <literal>LIMIT</literal> Clause @@ -739,45 +778,6 @@ OFFSET start - - <literal>DISTINCT</literal> Clause - - - If DISTINCT is specified, all duplicate rows are - removed from the result set (one row is kept from each group of - duplicates). ALL specifies the opposite: all rows are - kept; that is the default. - - - - DISTINCT ON ( expression [, ...] ) - keeps only the first row of each set of rows where the given - expressions evaluate to equal. The DISTINCT ON - expressions are interpreted using the same rules as for - ORDER BY (see above). Note that the first - row of each set is unpredictable unless ORDER - BY is used to ensure that the desired row appears first. For - example, - -SELECT DISTINCT ON (location) location, time, report - FROM weather_reports - ORDER BY location, time DESC; - - retrieves the most recent weather report for each location. But - if we had not used ORDER BY to force descending order - of time values for each location, we'd have gotten a report from - an unpredictable time for each location. - - - - The DISTINCT ON expression(s) must match the leftmost - ORDER BY expression(s). The ORDER BY clause - will normally contain additional expression(s) that determine the - desired precedence of rows within each DISTINCT ON group. - - - <literal>FOR UPDATE</literal> Clause