Skip to main content
Inspiring
July 22, 2009
Answered

inner join & outer join in one query

  • July 22, 2009
  • 1 reply
  • 2729 views

I have 11 tables, 10 of the tables need will always have a match on id, the 11th table may or my not have a match. I need to print info from the 10 tables with a matching id and information from the 11th table if a record is found.

Please help.

This topic has been closed for replies.
Correct answer ilssac

There is nothing wrong with having 10 inner joins and 1 outer join.

The syntax could look something like this in ANSII form:

FROM

  1Table INNER JOIN

  2Table ON (1Table.key = 2Table.KEY) INNER JOIN

  3Table ON (1Table.key = 3Table.KEY) INNER JOIN

  4Table ON (1TAble.key = 4Table.key) INNER JOIN

  5Table ON (1Table.key = 5table.key) INNER JOIN

  6Table ON (1Table.key = 6table.key) INNER JOIN

  7Table ON (1Table.key = 7Table.key) INNER JOIN

  8Table ON (1Table.key = 8Table.key) INNER JOIN

  9Table ON (1Table.key = 9Table.key) INNER JOIN

  10Table ON (1Table.key = 10Tablekey) LEFT OUTER JOIN

  11Table ON (1Table.key = 11Table.key)

You can use more paretheses to group the results if you like.

When building a relationship this complex the best process is to do it one table at a time.

Build the query to correctly return the desired results from the first table.  Then add the second and confirm it is still returning the desired results.  Continue to add the tables one at a time, testing all along the way.

1 reply

ilssac
ilssacCorrect answer
Inspiring
July 22, 2009

There is nothing wrong with having 10 inner joins and 1 outer join.

The syntax could look something like this in ANSII form:

FROM

  1Table INNER JOIN

  2Table ON (1Table.key = 2Table.KEY) INNER JOIN

  3Table ON (1Table.key = 3Table.KEY) INNER JOIN

  4Table ON (1TAble.key = 4Table.key) INNER JOIN

  5Table ON (1Table.key = 5table.key) INNER JOIN

  6Table ON (1Table.key = 6table.key) INNER JOIN

  7Table ON (1Table.key = 7Table.key) INNER JOIN

  8Table ON (1Table.key = 8Table.key) INNER JOIN

  9Table ON (1Table.key = 9Table.key) INNER JOIN

  10Table ON (1Table.key = 10Tablekey) LEFT OUTER JOIN

  11Table ON (1Table.key = 11Table.key)

You can use more paretheses to group the results if you like.

When building a relationship this complex the best process is to do it one table at a time.

Build the query to correctly return the desired results from the first table.  Then add the second and confirm it is still returning the desired results.  Continue to add the tables one at a time, testing all along the way.

Cozmo2Author
Inspiring
July 23, 2009

Thank you! It worked perfectly.