MSQuery: Err Msg: "Query Can Have Only One Outer Join"

ID: Q115340

The information in this article applies to:

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

1. 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

2. On the File menu, click Save As. Save the file in the dBASE file
   format, and name it EMPA.DBF.

3. 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

4. On the File menu, click Save As. Save the file in the dBASE file
   format, and name EMPB.DBF.

Creating Two Outer Joins

1. Start Microsoft Query, and click New Query on the File menu.

2. In the Select Data Source dialog box, choose dBASE files, and click

   Use.

3. 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.

4. 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.

5. 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.

6. Click the View SQL button on the toolbar.

   The following SQL statement will be displayed:

      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}

7. Starting from the "ON" portion of the statement, modify the SQL
   statement so that it matches the following statement:

      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.}

8. In the SQL Statement dialog box, choose OK.

9. When you get the "SQL Query can't be represented graphically. Continue

   anyway?" message, choose OK.

You will then have your double outer join. The results are below:

   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

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.

REFERENCES

"Microsoft Query User's Guide," pages 102-113

Additional query words: 5.00 howto

Keywords          : kbdta xlquery 
Version           : WINDOWS:97,7.0,5.0
Platform          : WINDOWS

Last Reviewed: January 8, 1999