1-Many Relationship X 5

Posted on 2011-09-07
Last Modified: 2012-05-12
Thought I had a simple project, but as I've gotten into it ... just cant find a solution.  Hopefully it is an easy fix.  I would appreciate any help.

We have 6 Excel spreadsheets that I wanted to import into an Access database in order to create queries & reports.  Each file has common IDs (project) with which to identify the data from table to table.  Sounds simple enough ...  While the initial table (list of projects - Table1) has a Primary Key (ID), the other tables all can list that ID any number of times so I dont have Primary Keys for those tables.  Simplified ...

Table 1 (Project) - ID, Office, Fund
Table 2 (Proj Data) - ID, Priority, Percentage (of Proj) ... i.e. 100% = 1 record; 50%/50% = 2 records etc)
Table 3 (Ops) - ID, Category, Qty, Cost (each item would be a separate record under each project ... same for tables 4,5&6)
Table 4 (Labor) - ID, Employee(s), Hrs, Salary
Table 5 (Vehicles) - ID, License#(s), Cost
Table 6 (Cell phones) - ID, Cell#(s), Cost

I created all of the relationships (1-many from Table 1 to the others) and then created a query based on those relationships.  There were many duplicates and not at all what we wanted.

Next, created individual queries adding one table at a time (i.e. Table 1+2, 1&2+3 etc) and this worked out somewhat better but still not quite right.

Current Output
While this is correct based on what I asked (and there are NO exact duplicates),  In this example (one project), there are 2 priorities (each with its % of project), 0 Ops, 2 Employees, 2 Vehicles and 0 Cell Phones.  There are calculations in the queries which calculate vehicle, salary etc costs based on the % of each priority which works great ... but as you can see, each employee is listed twice under each priority as is each vehicle.

As I said, this is a very simple example ... there are some projects which have up to 5 priorities, 20-30 employees, many vehicles etc.  But, I am very confident that if we can figure out how to format the queries to fix this particular example ... it will carry over to all.

Really appreciate any assistance that you can provide.  Thanks.    
Question by:PhxDB
LVL 40

Assisted Solution

als315 earned 100 total points
ID: 36497720
It is normal for your case - you have "star" structure of tables. When you combine different "beams" in one query - you will get your result. In your case better will be to make report (or form) with subreports for every "beam" (table).
When you have "chain" structure (project-employee-cell#), your queries can work.
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36497732
Try to use more descriptive names for your keys.

Naming them all "ID" is confusing
...make sense...?

I think a sample spreadsheet and DB would have been easier to follow...

LVL 26

Assisted Solution

Nick67 earned 300 total points
ID: 36497917
You are having grief with data normalization.
There's a good tutorial here

Essentially, there should be no duplicates in Table1
Do yourself a favor and rename ID to ProjectID on all the tables
Now, in Tables 2-6 add a column.
Call them ProjectDataID, OpsID, LaborID, VehicleID, and PhonesID
Fill these columns with sequential numbers.

Now, you should be able to relate each table on ProjectID.

If you are not seeing what you want in your queries, you'll have to look at your data.
But, in a nutshell, if the data is good, you should be somewhat normalized

Now, if you were going to fully normalize it, you'd need more tables (vehicles, employees, cellphones ect) but you'll be started
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

LVL 44

Assisted Solution

GRayL earned 100 total points
ID: 36497938
Each table should have its own primary key.  It may store a foreign key as many times as needed.  In your case, it appears that you have a primary key in table Projects named ID.  It should be named ProjID.  If in fact that same ID exists in all the other tables, the field name should be changed to ProjID, and your reference to that field in any of the other tables should be as a foreign key - ProjID

Now in the table ProjData it should have a pk - ProjDataID, as well as the foreign key ProjID, and so on down the line.

There is a reasonable amount of help in A2003 - type in - database design - for a start.

Author Comment

ID: 36505510
Thanks Guys.  Lots of good information!  Will have to do some studying and maybe re-thinking.

For the record, I did have "ProjID" for that field in each table.  I have now added Primary Keys to each table and numbered them sequentially.  Re-ran the queries and still ended up with the exact same records.

Instead of the screenprint on the original post ... this is basically what we want the query to show.

Desired Format
Of course it could be aligned differently, but the bottom line is that within each Project/Priority combination, there should be only 1 Bill Smith, 1 Veh# 423-921 etc.

Beginning to think that als315 was exactly correct ... but gonna try to find a way.  Any thoughts?  Thanks again.
LVL 26

Accepted Solution

Nick67 earned 300 total points
ID: 36505708
Without seeing the data, there isn't much I can offer.
I have pointed you at data normalization tutorials.
Ultimately, if your queries aren't returning the data the way you want them, it's becuase your data isn't structured right.
If Bill Smith can appear with different priorities, then Bill Smith doesn't have a relationship with ProjectID, he has a Relationship with Project Data, perhaps.

Working your data down until it is fully normalized.
Its worth the effort.
This may be the structure that results
Project <---> ProjData on ProjID
                     ProjData <------>Labor on ProjDataID
The employee has an indirect relationship with the project, through project data.

Work your data down until it is fully normalized.  It's a fundamental skill and requirement

Author Comment

ID: 36506076
Thanks Nick - Like I said you have given me lots to work with here.  Will definitely look further into normalization.

Author Closing Comment

ID: 36506096
While my problem has not been solved, these guys gave me alot of good information to help me try to find a solution.

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question