11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.16 2001/01/0915:48:18 momjian Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/sql.sgml,v 1.17 2001/01/0916:05:21 momjian Exp $
33-->
44
55 <chapter id="sql">
@@ -1058,10 +1058,20 @@ select sname, pname from supplier
10581058 item that occurs in a FROM clause and before any WHERE, GROUP BY,
10591059 or HAVING clause. Other table references, including table names or
10601060 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.
10651075 </para>
10661076
10671077 <variablelist>
@@ -1081,37 +1091,35 @@ select sname, pname from supplier
10811091respectively, and returns a joined table containing a cross
10821092product, NxM, of joined rows. For each row R1 of T1, each row
10831093R2 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.
10851096</para>
10861097</listitem>
10871098</varlistentry>
10881099
10891100<varlistentry>
1090- <term>Qualified JOINs</term>
1101+ <term>Qualified JOINs</term>
10911102 <listitem>
1103+
10921104<cmdsynopsis>
10931105<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>
10971108<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>
11021113</group>
1103- <arg> OUTER </arg>
1114+ <arg choice="opt" > OUTER </arg>
11041115 </arg>
1105- </group>
1106- </arg>
1116+ </group>
11071117<command> JOIN </command>
11081118<arg choice="req"> <replaceable class="parameter">T2</replaceable> </arg>
1109- <arg choice="req">
1110- <group>
1119+ <group choice="req">
11111120<arg> ON <replaceable>search condition</replaceable></arg>
11121121<arg> USING ( <replaceable>join column list</replaceable> ) </arg>
1113- </group>
1114- </arg>
1122+ </group>
11151123<arg choice="plain"> ... </arg>
11161124</cmdsynopsis>
11171125
@@ -1122,9 +1130,6 @@ select sname, pname from supplier
11221130column names, which the joined tables must have in common, and joins
11231131the tables on those columns, resulting in a joined table having one
11241132column 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 resulttable returned.
11281133</para>
11291134
11301135<!-- begin join semantics -->
@@ -1226,42 +1231,37 @@ select sname, pname from supplier
12261231<varlistentry>
12271232 <term>NATURAL JOINs</term>
12281233 <listitem>
1234+
12291235<cmdsynopsis>
12301236<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>
12351240<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>
12401245</group>
1241- <arg> OUTER </arg>
1246+ <arg choice="opt" > OUTER </arg>
12421247 </arg>
1243- </group>
1244- </arg>
1245- <command> JOIN </command>
1248+ </group>
1249+ <command> JOIN </command>
12461250<arg choice="req"> <replaceable class="parameter">T2</replaceable> </arg>
12471251</cmdsynopsis>
12481252
12491253<para>
12501254A natural join creates a joined table where every pair of matching
12511255column names between the two tables are merged into one column. The
12521256join 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.
12551258</para>
12561259</listitem>
12571260</varlistentry>
12581261
1259- <varlistentry>
1260- <term>UNION JOIN</term>
1261- <listitem><para>Deprecated.</para></listitem>
1262- </varlistentry>
12631262 </variablelist>
12641263
1264+
12651265 </sect3>
12661266
12671267 <sect3>