⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.sgml

📁 关系型数据库 Postgresql 6.5.2
💻 SGML
📖 第 1 页 / 共 2 页
字号:
<refentry id="SQL-SELECT"> <refmeta>  <refentrytitle>SELECT  </refentrytitle>  <refmiscinfo>SQL - Language Statements</refmiscinfo> </refmeta> <refnamediv>  <refname>SELECT  </refname>  <refpurpose>   Retrieve rows from a table or view.  </refpurpose></refnamediv> <refsynopsisdiv>  <refsynopsisdivinfo>   <date>1998-09-24</date>  </refsynopsisdivinfo>  <synopsis>SELECT [ALL|DISTINCT [ON <replaceable class="PARAMETER">column</replaceable>] ]    <replaceable class="PARAMETER">expression</replaceable> [ AS   <replaceable class="PARAMETER">name</replaceable> ] [, ...]    [ INTO [TEMP] [TABLE] <replaceable class="PARAMETER">new_table</replaceable> ]    [ FROM <replaceable class="PARAMETER">table</replaceable>   [<replaceable class="PARAMETER">alias</replaceable> ] [, ...] ]    [ WHERE <replaceable class="PARAMETER">condition</replaceable> ]    [ GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...] ]    [ HAVING <replaceable class="PARAMETER">condition</replaceable> [, ...] ]    [ { UNION [ALL] | INTERSECT | EXCEPT } <replaceable    class="PARAMETER">select</replaceable> ]    [ ORDER BY <replaceable class="PARAMETER">column</replaceable> [ ASC | DESC ] [, ...] ]    [ FOR UPDATE [OF class_name...]]    [ LIMIT count [OFFSET|, count]]  </synopsis>    <refsect2 id="R2-SQL-SELECT-1">   <refsect2info>    <date>1998-09-24</date>   </refsect2info>   <title>    Inputs   </title>      <para>    <variablelist>     <varlistentry>      <term>       <replaceable class="PARAMETER">expression</replaceable>      </term>      <listitem>       <para>	The name of a table's column or an expression.       </para>      </listitem>     </varlistentry>          <varlistentry>      <term>       <replaceable class="PARAMETER">name</replaceable>      </term>      <listitem>       <para>	Specifies another name for a column or an expression using	the AS clause. <replaceable class="PARAMETER">name</replaceable>	cannot be used in the WHERE	condition. It can, however, be referenced in associated	ORDER BY or GROUP BY clauses.       </para>      </listitem>     </varlistentry>         <varlistentry>     <term>     TEMP     </term>     <listitem>      <para>	The table is created unique to this session, and is	automatically dropped on session exit.      </para>     </listitem>    </varlistentry>     <varlistentry>      <term>       <replaceable class="PARAMETER">new_table</replaceable>      </term>      <listitem>       <para>	If the INTO TABLE clause is specified, the result of the	query will be stored in another table with the indicated	name.	The target table (<replaceable class="PARAMETER">new_table</replaceable>) will	be created automatically and should not exist before this command.        Refer to <command>SELECT INTO</command> for more information.	<note>	 <para>	  The <command>CREATE TABLE AS</command> statement will also	  create a new  table from a select query.	 </para>	</note>       </para>      </listitem>     </varlistentry>          <varlistentry>      <term>       <replaceable class="PARAMETER">table</replaceable>      </term>      <listitem>       <para>	The name of an existing table referenced by the FROM clause.       </para>      </listitem>     </varlistentry>          <varlistentry>      <term>       <replaceable class="PARAMETER">alias</replaceable>      </term>      <listitem>       <para>	An alternate name for the preceding	<replaceable class="PARAMETER">table</replaceable>.	It is used for brevity or to eliminate ambiguity for joins	within a single table.       </para>      </listitem>     </varlistentry>          <varlistentry>      <term>       <replaceable class="PARAMETER">condition</replaceable>      </term>      <listitem>       <para>	A boolean expression giving a result of true or false.	See the WHERE clause.       </para>      </listitem>     </varlistentry>          <varlistentry>      <term>       <replaceable class="PARAMETER">column</replaceable>      </term>      <listitem>       <para>	The name of a table's column.       </para>      </listitem>     </varlistentry>          <varlistentry>      <term>       <replaceable class="PARAMETER">select</replaceable>      </term>      <listitem>       <para>	A select statement with all features except the ORDER BY clause.       </para>      </listitem>     </varlistentry>         </variablelist>   </para>  </refsect2>    <refsect2 id="R2-SQL-SELECT-2">   <refsect2info>    <date>1998-09-24</date>   </refsect2info>   <title>    Outputs   </title>   <para>		<variablelist>	 <varlistentry>	  <term>	   Rows	  </term>	  <listitem>	   <para>		The complete set of rows resulting from the query specification.	   </para>	  </listitem>	 </varlistentry>	 	 <varlistentry>	  <term>	   <returnvalue><replaceable>count</replaceable></returnvalue>	  </term>	  <listitem>	   <para>		The count of rows returned by the query.	   </para>	  </listitem>	 </varlistentry>	</variablelist>   </para>  </refsect2> </refsynopsisdiv>  <refsect1 id="R1-SQL-SELECT-1">  <refsect1info>   <date>1998-09-24</date>  </refsect1info>  <title>   Description  </title>  <para>   <command>SELECT</command> will return rows from one or more tables.   Candidates for selection are rows which satisfy the WHERE condition;   if WHERE is omitted, all rows are candidates.</para>  <para>   <command>DISTINCT</command> will eliminate all duplicate rows from the   selection.   <command>DISTINCT ON <replaceable class="PARAMETER">column</replaceable></command> will eliminate all duplicates in the specified column; this isequivalent to using <command>GROUP BY <replaceable     class="PARAMETER">column</replaceable></command>.  <command>ALL</command> will return all candidate rows,including duplicates.</para>  <para>   The GROUP BY clause allows a user to divide a table   conceptually into groups. (See GROUP BY clause).</para>     <para>   The HAVING clause specifies a grouped table derived by the   elimination of groups from the result of the previously   specified clause. (See HAVING clause).</para>     <para>   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)</para>     <para>   The UNION clause allows the result to be the collection of rows   returned by the queries involved. (See UNION clause).</para>     <para>   The INTERSECT give you the rows that are common to both queries.   (See INTERSECT clause).</para>     <para>   The EXCEPT give you the rows in the upper query not in the lower query.   (See EXCEPT clause).</para>     <para>   The FOR UPDATE clause allows the SELECT statement to perform    exclusive locking of selected rows.   (See EXCEPT clause).</para>     <para>   The LIMIT...OFFSET clause allows control over which rows are   returned by the query.</para>     <para>   You must have SELECT privilege to a table to read its values   (See <command>GRANT</command>/<command>REVOKE</command> statements).</para>     <refsect2 id="R2-SQL-WHERE-2">   <refsect2info>    <date>1998-09-24</date>   </refsect2info>   <title>    WHERE Clause   </title>   <para>    The optional WHERE condition has the general form:        <synopsis>WHERE <replaceable class="PARAMETER">expr</replaceable> <replaceableclass="PARAMETER">ETER">c</replaceable>e<replaceable class="PARAMETER">"PAR</replaceable>replaceable> [ <replaceableclass="PARAMETER">log_op</replaceable> ... ]    </synopsis>        where <replaceable class="PARAMETER">cond_op</replaceable> can be    one of: =, &lt;, &lt;=, &gt;, &gt;= or &lt;&gt;,    a conditional operator like ALL, ANY, IN, LIKE, et cetera or a    locally-defined operator,     and <replaceable class="PARAMETER">log_op</replaceable> 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.   </para>  </refsect2>    <refsect2 id="R2-SQL-GROUPBY-2">   <refsect2info>    <date>1998-09-24</date>   </refsect2info>   <title>    GROUP BY Clause   </title>   <para>    GROUP BY specifies a grouped table derived by the application    of this clause:    <synopsis>GROUP BY <replaceable class="PARAMETER">column</replaceable> [, ...]    </synopsis></para>    <para>     GROUP BY will condense into a single row all rows that share the same values for the     grouped columns; aggregates return values derived from all rows that make up the group.  The value returned for an ungrouped     and unaggregated column is dependent on the order in which rows happen to be read from the database.    </para></refsect2>      <refsect2 id="R2-SQL-HAVING-2">   <refsect2info>    <date>1998-09-24</date>   </refsect2info>   <title>    HAVING Clause   </title>   <para>    The optional HAVING condition has the general form:        <synopsis>HAVING <replaceable class="PARAMETER">cond_expr</replaceable>    </synopsis>        where <replaceable class="PARAMETER">cond_expr</replaceable> is the same    as specified for the WHERE clause.</para>       <para>    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</replaceable>.</para>       <para>    Each column referenced in <replaceable class="PARAMETER">cond_expr</replaceable> shall unambiguously    reference a grouping column.   </para>  </refsect2>    <refsect2 id="R2-SQL-ORDERBYCLAUSE-2">   <refsect2info>    <date>1998-09-24</date>   </refsect2info>   <title>    ORDER BY Clause   </title>   <para>    <synopsis>ORDER BY <replaceable class="PARAMETER">column</replaceable> [ ASC | DESC ] [, ...]    </synopsis></para>       <para>    <replaceable class="PARAMETER">column</replaceable> can be either a column    name or an ordinal number.</para>   <para>    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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -