1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.16 2001/01/09 15:48:18 momjian Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.17 2001/01/09 16:05:21 momjian Exp $
3
3
-->
4
4
5
5
<chapter id="sql">
@@ -1058,10 +1058,20 @@ select sname, pname from supplier
1058
1058
item that occurs in a FROM clause and before any WHERE, GROUP BY,
1059
1059
or HAVING clause. Other table references, including table names or
1060
1060
other JOIN clauses, may be included in the FROM clause if separated
1061
- by commas. A JOIN of two tables is logically like any other
1062
- table listed in the FROM clause. A JOINed table can only be JOINed
1063
- to additional tables in a Qualified JOIN as indicated by the
1064
- elipses below.
1061
+ by commas. JOINed tables are logically like any other
1062
+ table listed in the FROM clause.
1063
+ </para>
1064
+
1065
+ <para>
1066
+ JOINs of all types can be chained together or nested where either or both of
1067
+ <replaceable class="parameter">T1</replaceable> and
1068
+ <replaceable class="parameter">T2</replaceable> may be JOINed tables.
1069
+ A Qualified JOIN may be JOINed to another table (or JOINed table)
1070
+ following its join specification, which consists of either an
1071
+ ON <replaceable>search condition</replaceable> or
1072
+ USING ( <replaceable>join column list</replaceable> ) clause.
1073
+ Parenthesis can be used around JOIN clauses to control the order
1074
+ of JOINs which are otherwise processed left to right.
1065
1075
</para>
1066
1076
1067
1077
<variablelist>
@@ -1081,37 +1091,35 @@ select sname, pname from supplier
1081
1091
respectively, and returns a joined table containing a cross
1082
1092
product, NxM, of joined rows. For each row R1 of T1, each row
1083
1093
R2 of T2 is joined with R1 to yield a joined table row JR
1084
- consisting of all fields in R1 and R2.
1094
+ consisting of all fields in R1 and R2. A CROSS JOIN is
1095
+ essentially an INNER JOIN ON TRUE.
1085
1096
</para>
1086
1097
</listitem>
1087
1098
</varlistentry>
1088
1099
1089
1100
<varlistentry>
1090
- <term>Qualified JOINs</term>
1101
+ <term>Qualified JOINs</term>
1091
1102
<listitem>
1103
+
1092
1104
<cmdsynopsis>
1093
1105
<arg choice="req"> <replaceable class="parameter">T1</replaceable> </arg>
1094
- <arg>
1095
- <group>
1096
- <arg choice="plain"> INNER </arg>
1106
+ <group choice="opt">
1107
+ <arg choice="opt"> INNER </arg>
1097
1108
<arg>
1098
- <group>
1099
- <arg> LEFT </arg>
1100
- <arg> RIGHT </arg>
1101
- <arg> FULL </arg>
1109
+ <group choice="req" >
1110
+ <arg choice="plain" > LEFT </arg>
1111
+ <arg choice="plain" > RIGHT </arg>
1112
+ <arg choice="plain" > FULL </arg>
1102
1113
</group>
1103
- <arg> OUTER </arg>
1114
+ <arg choice="opt" > OUTER </arg>
1104
1115
</arg>
1105
- </group>
1106
- </arg>
1116
+ </group>
1107
1117
<command> JOIN </command>
1108
1118
<arg choice="req"> <replaceable class="parameter">T2</replaceable> </arg>
1109
- <arg choice="req">
1110
- <group>
1119
+ <group choice="req">
1111
1120
<arg> ON <replaceable>search condition</replaceable></arg>
1112
1121
<arg> USING ( <replaceable>join column list</replaceable> ) </arg>
1113
- </group>
1114
- </arg>
1122
+ </group>
1115
1123
<arg choice="plain"> ... </arg>
1116
1124
</cmdsynopsis>
1117
1125
@@ -1122,9 +1130,6 @@ select sname, pname from supplier
1122
1130
column names, which the joined tables must have in common, and joins
1123
1131
the tables on those columns, resulting in a joined table having one
1124
1132
column for each common column and all of the other columns from both tables.
1125
- Like all SELECT queries, the <replaceable>select list</replaceable> of the
1126
- SELECT query, before the FROM clause, decides which columns from the joined
1127
- table are in the result table returned.
1128
1133
</para>
1129
1134
1130
1135
<!-- begin join semantics -->
@@ -1226,42 +1231,37 @@ select sname, pname from supplier
1226
1231
<varlistentry>
1227
1232
<term>NATURAL JOINs</term>
1228
1233
<listitem>
1234
+
1229
1235
<cmdsynopsis>
1230
1236
<arg choice="req"> <replaceable class="parameter">T1</replaceable> </arg>
1231
- <arg>
1232
- <arg choice="plain"> NATURAL </arg>
1233
- <group>
1234
- <arg choice="plain"> INNER </arg>
1237
+ <arg choice="plain"> NATURAL </arg>
1238
+ <group choice="opt">
1239
+ <arg choice="opt"> INNER </arg>
1235
1240
<arg>
1236
- <group>
1237
- <arg> LEFT </arg>
1238
- <arg> RIGHT </arg>
1239
- <arg> FULL </arg>
1241
+ <group choice="req" >
1242
+ <arg choice="plain" > LEFT </arg>
1243
+ <arg choice="plain" > RIGHT </arg>
1244
+ <arg choice="plain" > FULL </arg>
1240
1245
</group>
1241
- <arg> OUTER </arg>
1246
+ <arg choice="opt" > OUTER </arg>
1242
1247
</arg>
1243
- </group>
1244
- </arg>
1245
- <command> JOIN </command>
1248
+ </group>
1249
+ <command> JOIN </command>
1246
1250
<arg choice="req"> <replaceable class="parameter">T2</replaceable> </arg>
1247
1251
</cmdsynopsis>
1248
1252
1249
1253
<para>
1250
1254
A natural join creates a joined table where every pair of matching
1251
1255
column names between the two tables are merged into one column. The
1252
1256
join specification is effectively a USING clause containing all the
1253
- common column names and is otherwise like a Qualified JOIN except
1254
- additional JOINs to the JOINed table are not permitted.
1257
+ common column names and is otherwise like a Qualified JOIN.
1255
1258
</para>
1256
1259
</listitem>
1257
1260
</varlistentry>
1258
1261
1259
- <varlistentry>
1260
- <term>UNION JOIN</term>
1261
- <listitem><para>Deprecated.</para></listitem>
1262
- </varlistentry>
1263
1262
</variablelist>
1264
1263
1264
+
1265
1265
</sect3>
1266
1266
1267
1267
<sect3>
0 commit comments