Microsoft KB Archive/115340

= "Query Can Have Only One Outer Join" =

Article ID: 115340

Article Last Modified on 8/15/2003

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition
 * Microsoft Excel 98 for Macintosh
 * Microsoft Query 2000

-



This article was previously published under Q115340





SYMPTOMS
In Microsoft Query, if you attempt to create more than one outer join, you will receive the following error message:

Query can have only one outer join



CAUSE
Microsoft Query is limited to one outer join between two tables

NOTE: Microsoft Query can perform several inner joins and/or a single outer join in a query.



WORKAROUND
To work around this limit, you can create multiple outer joins by modifying the SQL statement containing the single outer join so that it performs multiple outer joins.

After you make the modification, Microsoft Query will not be able to Graphically display the multiple outer joins, but it will be able to display the results from the query in the Data pane.

WARNING: Your use or modification of the SQL statement provided in this article is at your own risk. Microsoft provides this SQL statement "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. Microsoft does not support modifications of the SQL statement to suit specific customer requirements.

The following is an example of a double outer join using two related dBASE tables. In order for the example to work correctly, you must have a data source installed for the dBASE file format.

Creating Sample Databases
  In Microsoft Excel, create the following table:      A1: FIRSTNAME     B1: LASTNAME       C1: LETTER A2: John         B2: Smith          C2: a      A3: Sam           B3: Smith          C3:b A4: Mike         B4: Smith          C4: c      A5: Jack          B5: Johnson        C5: d      A6: John          B6: Johnson        C6: e      A7: Sam           B7: Johnson        C7: f      A8: Mike          B8: Johnson        C8: g                         On the File menu, click Save As. Save the file in the dBASE file format, and name it EMPA.DBF.  On a new worksheet, create another table with the following information:      A1: FIRSTNAME     B1: LASTNAME       C1: COUNT A2: Sam          B2: Johnson        C2: 6 A3: Mike         B3: Johnson        C3: 7 A4: George       B4: Smith          C4: 1 A5: Sam          B5: Smith          C5: 2 A6: Mike         B6: Smith          C6: 3  On the File menu, click Save As. Save the file in the dBASE file format, and name EMPB.DBF.</ol>

Creating Two Outer Joins
<ol> Start Microsoft Query, and click New Query on the File menu.</li> In the Select Data Source dialog box, choose dBASE files, and click Use.</li> In the Add Tables dialog box, add the EMPA.DBF and EMPB.DBF dBASE files that you created in the "Creating Sample Databases" section above, and then click Close.</li> On the Table menu, click Joins. In the Joins dialog box, click empa.FIRSTNAME in the Left list, click = in the Operator list, and click empb.FIRSTNAME in the Right list. Select the second option in the Join Includes group to specify a LEFT OUTER join, and then click ADD, and then Close.</li> Double-click the * for the empa table, then double-click the * for the empb table.

All of the fields will be added to the query.</li>  Click the View SQL button on the toolbar.

The following SQL statement will be displayed: <pre class="fixed_text">     SELECT empa.FIRSTNAME, empa.LASTNAME, empa.LETTER, empb.FIRSTNAME, empb.LASTNAME, empb.COUNT FROM {oj c:\wow\empa.dbf empa LEFT OUTER JOIN c:\wow\empb.dbf empb ON empa.FIRSTNAME = empb.FIRSTNAME} </li>  Starting from the "ON" portion of the statement, modify the SQL statement so that it matches the following statement: <pre class="fixed_text">     SELECT empa.FIRSTNAME, empa.LASTNAME, empa.LETTER, empb.FIRSTNAME, empb.LASTNAME, empb.COUNT FROM {oj c:\wow\empa.dbf empa LEFT OUTER JOIN c:\wow\empb.dbf empb ON (empa.FIRSTNAME = empb.FIRSTNAME and     empa.LASTNAME=empb.LASTNAME.}                        </li> In the SQL Statement dialog box, choose OK.</li> When you get the "SQL Query can't be represented graphically. Continue anyway?" message, choose OK.</li></ol>

You will then have your double outer join. The results are below: <pre class="fixed_text">  FIRSTNAME  LASTNAME   LETTER   FIRSTNAME  LASTNAME  COUNT John      Smith       a   Sam        Smith       b        Sam        Smith     2 Mike      Smith       c        Mike       Smith     3 Jack      Johnson     d   John       Johnson     e   Sam        Johnson     f        Sam        Johnson   6 Mike      Johnson     g        Mike       Johnson   7

<div class="moreinformation_section">

MORE INFORMATION
Joins are used in Microsoft Query to associate tables using common fields. In a two table example, an outer join retrieves all the records from one table and only those records from the other table for which values in the joined fields are equal.

<div class="references_section">