Union query for three tables

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

I have a table that has DivisionNum and another table that
has LineNum. These two tables are bridged by a third
table that contains both DivisionNum and LineNum. How do
I create a union query that returns records for all three
tables?

Thanks
 
Dear Adam:

From the little information you give, I don't think UNION is the term
for what you want to do. Rather, I think you want to JOIN tables.
This is what makes queries work between tables that have
RELATIONSHIPS, whether you have defined those relationships or not.

There are several types of relationships: one-to-one, one-to-many,
and many-to-many. We need to find out which of these relationships
describe what your tables are doing before being at all definite as to
how to use them in a query.

Table1 - DivisionNum
Table2 - LineNum
Table3 - DivisionNum/LineNum

OK, this really makes it sound like you have a many-to-many
relationship between Table1 and Table2 with Table3 as a link table.

The terms I've used, rather than "bridged" and "union" are both
specific (at least among those with whom I often converse) and are
related to what I THINK you are doing.

Now, unless Table3 contains other columns besides DivisionNum and
LineNum then it's just going to say which Divisions are associated
with which Lines. For a starter, let's try this query and see if it
goes anywhere:

SELECT A.*, B.*
FROM Table1 A
INNER JOIN Table3 C ON C.DivisionNum = A.DivisionNum
INNER JOIN Table2 B ON B.LineNum = C.LineNum
ORDER BY A.DivisionNum, B.LineNum

Does this begin to give you what you're looking for?

The integrity of the data should probably be protected by declaring
your relationships between these tables. The main thing is that every
row in Table3 MUST have a valid DivisionNum in Table1 and a valid
LineNum in Table2. Ensuring this would be a very good thing, indeed!

Let me know if my wild guesses have produced anything of use to you.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Back
Top