Solved

1-Many Relationship X 5

Posted on 2011-09-07
8
259 Views
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.    
0
Comment
Question by:PhxDB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 40

Assisted Solution

by:als315
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.
0
 
LVL 74

Expert Comment

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

Naming them all "ID" is confusing
tblCustomers=CustomerID
tblOrders=OrderID
tblWatermellons=WatermellonID
...make sense...?


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

0
 
LVL 26

Assisted Solution

by:Nick67
Nick67 earned 300 total points
ID: 36497917
You are having grief with data normalization.
There's a good tutorial here
http://www.phlonx.com/resources/nf3/

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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Assisted Solution

by:GRayL
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.
0
 

Author Comment

by:PhxDB
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.
0
 
LVL 26

Accepted Solution

by:
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
....ect....
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
0
 

Author Comment

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

Author Closing Comment

by:PhxDB
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.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

740 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