<title>Pattern Matching with <function>LIKE</function></title>
<title>Pattern Matching with <function>LIKE</function></title>
<indexterm>
<primary>like</primary>
</indexterm>
<synopsis>
<synopsis>
<replaceable>string</replaceable> LIKE <replaceable>pattern</replaceable> <optional> ESCAPE <replaceable>escape-character</replaceable> </optional>
<replaceable>string</replaceable> LIKE <replaceable>pattern</replaceable> <optional> ESCAPE <replaceable>escape-character</replaceable> </optional>
<replaceable>string</replaceable> NOT LIKE <replaceable>pattern</replaceable> <optional> ESCAPE <replaceable>escape-character</replaceable> </optional>
<replaceable>string</replaceable> NOT LIKE <replaceable>pattern</replaceable> <optional> ESCAPE <replaceable>escape-character</replaceable> </optional>
@@ -145,6 +153,11 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
...
@@ -145,6 +153,11 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
<term>Qualified JOINs</term>
<term>Qualified JOINs</term>
<listitem>
<listitem>
<indexterm>
<primary>joins</primary>
<secondary>outer</secondary>
</indexterm>
<synopsis>
<synopsis>
<replaceable>T1</replaceable> { <optional>INNER</optional> | { LEFT | RIGHT | FULL } <optional>OUTER</optional> } JOIN <replaceable>T2</replaceable> ON <replaceable>boolean_expression</replaceable>
<replaceable>T1</replaceable> { <optional>INNER</optional> | { LEFT | RIGHT | FULL } <optional>OUTER</optional> } JOIN <replaceable>T2</replaceable> ON <replaceable>boolean_expression</replaceable>
<replaceable>T1</replaceable> { <optional>INNER</optional> | { LEFT | RIGHT | FULL } <optional>OUTER</optional> } JOIN <replaceable>T2</replaceable> USING ( <replaceable>join column list</replaceable> )
<replaceable>T1</replaceable> { <optional>INNER</optional> | { LEFT | RIGHT | FULL } <optional>OUTER</optional> } JOIN <replaceable>T2</replaceable> USING ( <replaceable>join column list</replaceable> )
...
@@ -187,6 +200,10 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
...
@@ -187,6 +200,10 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
</para>
</para>
<para>
<para>
<indexterm>
<primary>joins</primary>
<secondary>natural</secondary>
</indexterm>
Finally, NATURAL is a shorthand form of USING: it forms a USING
Finally, NATURAL is a shorthand form of USING: it forms a USING
list consisting of exactly those column names that appear in both
list consisting of exactly those column names that appear in both
input tables. As with USING, these columns appear only once in
input tables. As with USING, these columns appear only once in
...
@@ -213,6 +230,11 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
...
@@ -213,6 +230,11 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
<term>LEFT OUTER JOIN</term>
<term>LEFT OUTER JOIN</term>
<listitem>
<listitem>
<indexterm>
<primary>joins</primary>
<secondary>left</secondary>
</indexterm>
<para>
<para>
First, an INNER JOIN is performed. Then, for each row in T1
First, an INNER JOIN is performed. Then, for each row in T1
that does not satisfy the join condition with any row in
that does not satisfy the join condition with any row in
...
@@ -268,6 +290,10 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
...
@@ -268,6 +290,10 @@ FROM <replaceable>table_reference</replaceable> <optional>, <replaceable>table_r
<sect3 id="queries-subqueries">
<sect3 id="queries-subqueries">
<title>Subqueries</title>
<title>Subqueries</title>
<indexterm zone="queries-subqueries">
<primary>subqueries</primary>
</indexterm>
<para>
<para>
Subqueries specifying a derived table must be enclosed in
Subqueries specifying a derived table must be enclosed in
parentheses and <emphasis>must</emphasis> be named using an AS
parentheses and <emphasis>must</emphasis> be named using an AS
...
@@ -289,6 +315,16 @@ FROM (SELECT * FROM table1) AS alias_name
...
@@ -289,6 +315,16 @@ FROM (SELECT * FROM table1) AS alias_name
<sect3 id="queries-table-aliases">
<sect3 id="queries-table-aliases">
<title>Table and Column Aliases</title>
<title>Table and Column Aliases</title>
<indexterm zone="queries-table-aliases">
<primary>label</primary>
<secondary>table</secondary>
</indexterm>
<indexterm>
<primary>alias</primary>
<see>label</see>
</indexterm>
<para>
<para>
A temporary name can be given to tables and complex table
A temporary name can be given to tables and complex table
references to be used for references to the derived table in
references to be used for references to the derived table in
...
@@ -400,6 +436,10 @@ FROM (SELECT * FROM T1) DT1, T2, T3
...
@@ -400,6 +436,10 @@ FROM (SELECT * FROM T1) DT1, T2, T3
<sect2 id="queries-where">
<sect2 id="queries-where">
<title>WHERE clause</title>
<title>WHERE clause</title>
<indexterm zone="queries-where">
<primary>where</primary>
</indexterm>
<para>
<para>
The syntax of the WHERE clause is
The syntax of the WHERE clause is
<synopsis>
<synopsis>
...
@@ -482,6 +522,10 @@ FROM FDT WHERE
...
@@ -482,6 +522,10 @@ FROM FDT WHERE
<sect2 id="queries-group">
<sect2 id="queries-group">
<title>GROUP BY and HAVING clauses</title>
<title>GROUP BY and HAVING clauses</title>
<indexterm zone="queries-group">
<primary>group</primary>
</indexterm>
<para>
<para>
After passing the WHERE filter, the derived input table may be
After passing the WHERE filter, the derived input table may be
subject to grouping, using the GROUP BY clause, and elimination of
subject to grouping, using the GROUP BY clause, and elimination of
...
@@ -578,6 +622,11 @@ SELECT pid AS "Products",
...
@@ -578,6 +622,11 @@ SELECT pid AS "Products",
<sect1 id="queries-select-lists">
<sect1 id="queries-select-lists">
<title>Select Lists</title>
<title>Select Lists</title>
<indexterm>
<primary>select</primary>
<secondary>select list</secondary>
</indexterm>
<para>
<para>
As shown in the previous section,
As shown in the previous section,
the table expression in the <command>SELECT</command> command
the table expression in the <command>SELECT</command> command
...
@@ -620,6 +669,11 @@ SELECT tbl1.a, tbl2.b, tbl1.c FROM ...
...
@@ -620,6 +669,11 @@ SELECT tbl1.a, tbl2.b, tbl1.c FROM ...
<sect2 id="queries-column-labels">
<sect2 id="queries-column-labels">
<title>Column Labels</title>
<title>Column Labels</title>
<indexterm zone="queries-column-labels">
<primary>label</primary>
<secondary>column</secondary>
</indexterm>
<para>
<para>
The entries in the select list can be assigned names for further
The entries in the select list can be assigned names for further
processing. The <quote>further processing</quote> in this case is
processing. The <quote>further processing</quote> in this case is
...
@@ -652,6 +706,10 @@ SELECT a AS value, b + c AS sum FROM ...
...
@@ -652,6 +706,10 @@ SELECT a AS value, b + c AS sum FROM ...
<sect2 id="queries-distinct">
<sect2 id="queries-distinct">
<title>DISTINCT</title>
<title>DISTINCT</title>
<indexterm zone="queries-distinct">
<primary>distinct</primary>
</indexterm>
<para>
<para>
After the select list has been processed, the result table may
After the select list has been processed, the result table may
optionally be subject to the elimination of duplicates. The
optionally be subject to the elimination of duplicates. The
...
@@ -700,6 +758,16 @@ SELECT DISTINCT ON (<replaceable>expression</replaceable> <optional>, <replaceab
...
@@ -700,6 +758,16 @@ SELECT DISTINCT ON (<replaceable>expression</replaceable> <optional>, <replaceab
<sect1 id="queries-union">
<sect1 id="queries-union">
<title>Combining Queries</title>
<title>Combining Queries</title>
<indexterm zone="queries-union">
<primary>union</primary>
</indexterm>
<indexterm zone="queries-union">
<primary>intersection</primary>
</indexterm>
<indexterm zone="queries-union">
<primary>except</primary>
</indexterm>
<para>
<para>
The results of two queries can be combined using the set operations
The results of two queries can be combined using the set operations
union, intersection, and difference. The syntax is
union, intersection, and difference. The syntax is
...
@@ -757,6 +825,11 @@ SELECT DISTINCT ON (<replaceable>expression</replaceable> <optional>, <replaceab
...
@@ -757,6 +825,11 @@ SELECT DISTINCT ON (<replaceable>expression</replaceable> <optional>, <replaceab
<sect1 id="queries-order">
<sect1 id="queries-order">
<title>Sorting Rows</title>
<title>Sorting Rows</title>
<indexterm zone="queries-order">
<primary>sorting</primary>
<secondary>query results</secondary>
</indexterm>
<para>
<para>
After a query has produced an output table (after the select list
After a query has produced an output table (after the select list
has been processed) it can optionally be sorted. If sorting is not
has been processed) it can optionally be sorted. If sorting is not
...
@@ -817,6 +890,15 @@ SELECT a AS b FROM table1 ORDER BY a;
...
@@ -817,6 +890,15 @@ SELECT a AS b FROM table1 ORDER BY a;
<sect1 id="queries-limit">
<sect1 id="queries-limit">
<title>LIMIT and OFFSET</title>
<title>LIMIT and OFFSET</title>
<indexterm zone="queries-limit">
<primary>limit</primary>
</indexterm>
<indexterm zone="queries-limit">
<primary>offset</primary>
<secondary>with query results</secondary>
</indexterm>
<synopsis>
<synopsis>
SELECT <replaceable>select_list</replaceable> FROM <replaceable>table_expression</replaceable> <optional>ORDER BY <replaceable>sort_spec</replaceable></optional> <optional>LIMIT { <replaceable>number</replaceable> | ALL }</optional> <optional>OFFSET <replaceable>number</replaceable></optional>
SELECT <replaceable>select_list</replaceable> FROM <replaceable>table_expression</replaceable> <optional>ORDER BY <replaceable>sort_spec</replaceable></optional> <optional>LIMIT { <replaceable>number</replaceable> | ALL }</optional> <optional>OFFSET <replaceable>number</replaceable></optional>