Minor wording and formatting cleanups.
authorThomas G. Lockhart
Mon, 7 Sep 1998 15:54:08 +0000 (15:54 +0000)
committerThomas G. Lockhart
Mon, 7 Sep 1998 15:54:08 +0000 (15:54 +0000)
doc/src/sgml/ref/select.sgml

index 1f4818b8b0fb8eaea0ca55d1d85cb32871eb6746..ef47fa7d09afbfb70e11cee0e675240388252bb6 100644 (file)
-
-
-
-SELECT
-
-SQL - Language Statements
-
-
-
-SELECT
-
-
-Retrieve rows from a table or view
-
-
-
-1998-04-15
-
-
-
-
+
+  
+   SELECT
+  
+  SQL - Language Statements
+  
+   SELECT
+  
+  
+   Retrieve rows from a table or view.
+  
+  
+   1998-09-06
+  
+  
 SELECT [ALL|DISTINCT]
-    expression [AS name] [, ...]
-    [INTO [TABLE] intable]
-    [FROM table [alias] [, ...] ]
-    [WHERE condition]
-    [GROUP BY column [, ...] ]
-    [HAVING condition [, ...] ]
-    [UNION [ALL] select]
-    [ORDER BY column [ASC | DESC] [, ...] ]
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-Inputs</div> <div class="diff rem">-
-
-
-
-
-
-expression
-
-
-
-          The name of a table's column or an expression.
-
-
-
-
-
-
-name
-
-
-
-          Specifies another name for a column or an expression using
-          the AS clause. name cannot be used in the WHERE
-          condition. It can, however, be referenced in associated
-          ORDER BY or GROUP BY clauses.
-
-
-
-
-
-
-intable
-
-
-
-          If the INTO TABLE clause is specified, the result of the
-          query will be stored in another table with the indicated
-          name.
-If intable does not exist, it will be created automatically.
-
-
-
-The CREATE TABLE AS statement will also create a new table from a select query.
-
-
-
-
-
-
-
-
-table
-
-
-
-          The name of an existing table referenced by FROM clause.
-
-
-
-
-
-
-alias
-
-
-
-An alternate name for the preceeding table.
-Used for brevity or to eliminate ambiguity for joins within a single table.
-
-
-
-
-
-
-condition
-
-
-
-An expression leading to a boolean (true/false) result.
-See the WHERE clause.
-
-
-
-
-
-
-column
-
-
-
-          The name of a table's column.
-
-
-
-
-
-
-select
-
-
-
-A select statement with all features except the ORDER BY clause.
-
-
-
-
-
-
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-Outputs</div> <div class="diff rem">-
-
-
-
-   Rows
-
-
-
-The complete set of rows resulting from the query specification.
-
-
-
-
-
-
-count
-
-
-
-The count of rows returned by the query.
-
-
-
-
-
-
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-Description</div> <div class="diff rem">-
-
-SELECT is the principal means to access information
- in Postgres.
-
+    expression [AS name] [, ...]
+    [INTO [TABLE] intable]
+    [FROM table [alias] [, ...] ]
+    [WHERE condition]
+    [GROUP BY column [, ...] ]
+    [HAVING condition [, ...] ]
+    [UNION [ALL] select]
+    [ORDER BY column [ASC | DESC] [, ...] ]
+  
+  
+  
+   
+    1998-09-06
+   
+   </div> <div class="diff add">+    Inputs</div> <div class="diff add">+   
+   
+   
+    
+     
+      
+       expression
+      
+      
+       
+   The name of a table's column or an expression.
+       
+      
+     
+     
+     
+      
+       name
+      
+      
+       
+   Specifies another name for a column or an expression using
+   the AS clause. name
+   cannot be used in the WHERE
+   condition. It can, however, be referenced in associated
+   ORDER BY or GROUP BY clauses.
+       
+      
+     
+     
+     
+      
+       intable
+      
+      
+       
+   If the INTO TABLE clause is specified, the result of the
+   query will be stored in another table with the indicated
+   name.
+   If intable does
+   not exist, it will be created automatically.
+   
+   
+    
+     The CREATE TABLE AS statement will also
+     create a new  table from a select query.
+    
+   
+       
+      
+     
+     
+     
+      
+       table
+      
+      
+       
+   The name of an existing table referenced by the FROM clause.
+       
+      
+     
+     
+     
+      
+       alias
+      
+      
+       
+   An alternate name for the preceding
+   table.
+   It is used for brevity or to eliminate ambiguity for joins
+   within a single table.
+       
+      
+     
+     
+     
+      
+       condition
+      
+      
+       
+   A boolean expression giving a result of true or false.
+   See the WHERE clause.
+       
+      
+     
+     
+     
+      
+       column
+      
+      
+       
+   The name of a table's column.
+       
+      
+     
+     
+     
+      
+       select
+      
+      
+       
+   A select statement with all features except the ORDER BY clause.
+       
+      
+     
+     
+    
+   
+  
+  
+  
+   
+    1998-09-06
+   
+   </div> <div class="diff add">+    Outputs</div> <div class="diff add">+   
+   
+    
+     
+      Rows
+     
+     
+      
+       The complete set of rows resulting from the query specification.
+      
+     
+    
+    
+    
+     
+      count
+     
+     
+      
+       The count of rows returned by the query.
+      
+     
+    
+   
+   
+  
+  
+   1998-09-06
+  
+  </div> <div class="diff add">+   Description</div> <div class="diff add">+  
+  
    SELECT will get all rows which satisfy the WHERE condition
-   or all rows of a table if WHERE is omitted.
-
->
+   or all rows of a table if WHERE is omitted.
+   
+  >
    The GROUP BY clause allows a user to divide a table
-   conceptually into groups. (See GROUP BY clause).
-
+   conceptually into groups. (See GROUP BY clause).
+   
+  
    The HAVING clause specifies a grouped table derived by the
    elimination of groups from the result of the previously
-   specified clause. (See HAVING clause).
-
+   specified clause. (See HAVING clause).
+   
+  
    The ORDER BY clause allows a user to specify that he/she
    wishes the rows sorted according to the ASCending or 
-   DESCending mode operator. (See ORDER BY clause)
-
+   DESCending mode operator. (See ORDER BY clause)
+   
+  
    The UNION clause specifies a table derived from a Cartesian
-   product union join. (See UNION clause).
-
->
+   product union join. (See UNION clause).
+   
+  >
    You must have SELECT privilege to a table to read its values
-   (See GRANT/REVOKE statements).
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-WHERE clause</div> <div class="diff rem">-
-
-         The optional WHERE condition has the general form:
-
-
-WHERE expr cond_op expr [log_op ...]
-
-
-         where cond_op can be one of: =, <, <=, >, >=, <>
-         or a conditional operator like ALL, ANY, IN, LIKE, et cetera
-         and log_op can be one of: AND, OR, NOT.
-         The comparison returns either TRUE or FALSE and all
-         instances will be discarded
-         if the expression evaluates to FALSE.
-
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-GROUP BY clause</div> <div class="diff rem">-
-
+   (See GRANT/REVOKE statements).
+   
+  
+   
+    1998-09-06
+   
+   </div> <div class="diff add">+    WHERE clause</div> <div class="diff add">+   
+   
+    The optional WHERE condition has the general form:
+    
+    
+WHERE expr cond_op expr [log_op ...]
+    
+    
+    where cond_op can be
+    one of: =, <, <=, >, >=, <>
+    or a conditional operator like ALL, ANY, IN, LIKE, et cetera
+    and log_op can be one 
+    of: AND, OR, NOT.
+    The comparison returns either TRUE or FALSE and all
+    instances will be discarded
+    if the expression evaluates to FALSE.
+   
+  
+  
+  
+   
+    1998-09-06
+   
+   </div> <div class="diff add">+    GROUP BY clause</div> <div class="diff add">+   
+   
     GROUP BY specifies a grouped table derived by the application
     of the this clause:
->
-GROUP BY column> [, ...]
->
-
-="R2-SQL-HAVING-2">
->
-1998-04-15>
->
->
-HAVING clause
->
->
-         The optional HAVING condition has the general form:
-
-ynopsis>
-HAVING <REPLACEABLE CLASS="PARAMETER">cond_expr>
-ynopsis>
-
-         where cond_expr> is the same
-as specified for the WHERE clause.
-
-ara>
+    >
+     GROUP BY column> [, ...]
+    >
+    
+  ="R2-SQL-HAVING-2">
+   >
+    1998-09-06>
+   >
+   >
+    HAVING clause
+   >
+   >
+    The optional HAVING condition has the general form:
+    
+    ynopsis>
+HAVING <replaceable class="PARAMETER">cond_expr>
+    ynopsis>
+    
+    where cond_expr> is the same
+    as specified for the WHERE clause.
+    
+   ara>
     HAVING specifies a grouped table derived by the elimination
     of groups from the result of the previously specified clause
-    that do not meet the <REPLACEABLE CLASS="PARAMETER">cond_expr.
-
-ara>
-    Each column referenced in <REPLACEABLE CLASS="PARAMETER">cond_expr> shall unambiguously
+    that do not meet the <replaceable class="PARAMETER">cond_expr.
+    
+   ara>
+    Each column referenced in <replaceable class="PARAMETER">cond_expr> shall unambiguously
     reference a grouping column.
->
-2>
-
-="R2-SQL-ORDERBYCLAUSE-2">
->
-1998-04-15>
->
->
-ORDER BY clause
->
->
-ynopsis>
-ORDER BY <REPLACEABLE CLASS="PARAMETER">column> [ASC | DESC] [, ...]
->
-
->
-column> can be either a column
-name or an ordinal number.
->
+   >
+  2>
+  
+  ="R2-SQL-ORDERBYCLAUSE-2">
+   >
+    1998-09-06>
+   >
+   >
+    ORDER BY clause
+   >
+   >
+    ynopsis>
+ORDER BY <replaceable class="PARAMETER">column> [ASC | DESC] [, ...]
+    >
+    
+   >
+    column> can be either a column
+    name or an ordinal number.
+   >
     The ordinal numbers refers to the ordinal (left-to-right) position
     of the column. This feature makes it possible to define an ordering
     on the basis of a column that does not have a proper name.
     This is never absolutely necessary because it is always possible assign a name
     to a calculated column using the AS clause, e.g.:
-isting>
-SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
->
-
->
+    isting>
+     SELECT title, date_prod + 1 AS newlen FROM films ORDER BY newlen;
+    >
+    
+   >
     The columns in the ORDER BY must appear in the SELECT clause.
     Thus the following statement is illegal:
-isting>
-SELECT name FROM distributors ORDER BY code;
->
-
->
+    isting>
+     SELECT name FROM distributors ORDER BY code;
+    >
+    
+   >
     Optionally one may add the keyword DESC (descending)
     or ASC (ascending) after each column name in the ORDER BY clause.
-    If not specified, ASC is assumed by default.
-2>
-
-="R2-SQL-UNION-2">
->
-1998-04-15>
->
->
-UNION clause
->
->
-ynopsis>
-<REPLACEABLE CLASS="PARAMETER">table_query UNION [ALL] table_query>
-    [ORDER BY column> [ASC | DESC] [, ...] ]
-ynopsis>
-
-where
-   table_query>
-         specifies any select expression without an ORDER BY clause.
-
->
-   The UNION operator specifies a table derived from a Cartesian product.
-   The two tables that represent the direct operands of the UNION must
-   have the same number of columns, and corresponding columns must be
-   of compatible data types.
-
->
-   By default, the result of UNION does not contain any duplicate rows
-   unless the ALL clause is specified.
-
-ara>
-Multiple UNION operators in the same SELECT statement are evaluated left to right.
-Note that the ALL keyword is not global in nature, being applied only for the current pair of
-table results.
-
->
-
-="R1-SQL-SELECT-2">
->
-Usage
->
->
-
-
-    --Join table films with their distributors:
-    --
+    If not specified, ASC is assumed by default.
+  2>
+  
+  ="R2-SQL-UNION-2">
+   >
+    1998-09-06>
+   >
+   >
+    UNION clause
+   >
+   >
+    ynopsis>
+<replaceable class="PARAMETER">table_query UNION [ALL] table_query>
+     [ORDER BY column> [ASC | DESC] [, ...] ]
+    ynopsis>
+    
+    where
+    table_query>
+    specifies any select expression without an ORDER BY clause.
+    
+   >
+    The UNION operator specifies a table derived from a Cartesian product.
+    The two tables that represent the direct operands of the UNION must
+    have the same number of columns, and corresponding columns must be
+    of compatible data types.
+    
+   >
+    By default, the result of UNION does not contain any duplicate rows
+    unless the ALL clause is specified.
+    
+   ara>
+    Multiple UNION operators in the same SELECT statement are evaluated left to right.
+    Note that the ALL keyword is not global in nature, being applied only for the current pair of
+    table results.
+    
+  >
+  
+ ="R1-SQL-SELECT-2">
+  >
+   Usage
+  >
+  >
+   To join the table films with the table
+   distributors:
+  
+  
     SELECT f.title, f.did, d.name, f.date_prod, f.kind
         FROM distributors d, films f
-        WHERE f.did = d.did;
+        WHERE f.did = d.did
 
     title                    |did|name            | date_prod|kind
     -------------------------+---+----------------+----------+----------
@@ -382,11 +387,12 @@ Usage
     The King and I           |109|20th Century Fox|1956-08-11|Musical
     Das Boot                 |110|Bavaria Atelier |1981-11-11|Drama
     Bed Knobs and Broomsticks|111|Walt Disney     |          |Musical
-
-    
-
-    --sum column "len" of all films group by "kind":
-    --
+  
+  
+   To sum the column len of all films and group
+   the reults by kind:
+  
+  
     SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
 
     kind      |total
@@ -396,12 +402,14 @@ Usage
     Drama     | 14:28
     Musical   | 06:42
     Romantic  | 04:38
-
-
-
-    --sum column length of all films group by "kind"
-    --having total duration < 5 hours:
-    --
+  
+
+  
+   To sum the column len of all films, group
+   the reults by kind and show those group totals
+   that are less than 5 hours:
+  
+  
     SELECT kind, SUM(len) AS total
         FROM films
         GROUP BY kind
@@ -411,11 +419,13 @@ Usage
     ----------+------
     Comedy    | 02:58
     Romantic  | 04:38
-
-
-
-    --The following two examples are identicals:
-    --
+  
+  
+    The following two examples are identical ways of sorting the individual
+   results according to the contents of the second column
+   (name):
+  
+  
     SELECT * FROM distributors ORDER BY name;
     SELECT * FROM distributors ORDER BY 2;
 
@@ -434,29 +444,31 @@ Usage
     111|Walt Disney
     112|Warner Bros.
     108|Westward
-
-
-
-    --union of table distributors and table actors:
-    -- (only those that begin with letter W):
-    --
-    -- distributors:                     actors:
+  
+
+  
+   This example shows how to obtain the union of the tables
+   distributors and
+   actors, restricting the results to those that begin
+   with letter W in each table.  Only distinct rows are to be used, so the
+   ALL keyword is omitted:
+  
+  
+    --        distributors:                actors:
     --        did|name                     id|name
     --        ---+------------             --+--------------
     --        108|Westward                  1|Woody Allen
     --        111|Walt Disney               2|Warren Beatty
     --        112|Warner Bros.              3|Walter Matthau
     --        ...                           ...
-    --
-    --select only distinct rows (without ALL):
-    --
+
     SELECT distributors.name
     FROM   distributors
     WHERE  distributors.name LIKE 'W%'
     UNION
            SELECT actors.name
            FROM   actors
-           WHERE  actors.name LIKE 'W%';
+           WHERE  actors.name LIKE 'W%'
 
     name
     --------------
@@ -466,88 +478,91 @@ Usage
     Warren Beatty
     Westward
     Woody Allen
-
-
-
-
-
-</div> <div class="diff rem">-Compatibility</div> <div class="diff rem">-
-
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-<Acronym>SQL92</Acronym></div> <div class="diff rem">-
-
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-SELECT clause</div> <div class="diff rem">-
-
-In the SQL92 standard, the optional keyword "AS" is just noise and can be 
-omitted without affecting the meaning.
-The Postgres parser requires this keyword when
-renaming columns because the type extensibility features lead to parsing ambiguities
-in this context.
-
-
-In the SQL92 standard, the new column name specified in an
-"AS" clause may be referenced in GROUP BY and HAVING clauses. This is not currently
-allowed in Postgres.
-
-
-
-
-
-1998-04-15
-
-</div> <div class="diff rem">-UNION clause</div> <div class="diff rem">-
-
-The SQL92 syntax for UNION allows an additional CORRESPONDING BY clause:
- 
-table_query UNION [ALL]
-    [CORRESPONDING [BY (column [,...])]]
-    table_query
-
-
-
-The CORRESPONDING BY clause is not supported by Postgres.
-
-
-
-
-
-
-
-