473,419 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Q: How to relate field in table A to more than one other table

(Hope I can ask this clearly...)

I have three tables: tblPayments, tblCompanies, and tblPeople.
tblPayments contains a field called lngPayeeID that needs to relate to
records from tblCompanies and tblPeople. Why? Because a "payee"
(lngPayeeID) can be either a company (tblCompany.lngCompanyID) or a
person (tblPeople.lngPersonID).

I know how to relate tblPayments.lngPayeeID to a single table's field,
such as tblCompanies.lngCompanyID. I just can't figure out how to
relate it to two unlike tables (i.e., a payee can be a company or
person, which are both unrelated to each other).

Any suggestions are appreciated!
John
Nov 12 '05 #1
3 3668
"John" <so*********@hotmail.com> wrote in message
news:90**************************@posting.google.c om...
(Hope I can ask this clearly...)

I have three tables: tblPayments, tblCompanies, and tblPeople.
tblPayments contains a field called lngPayeeID that needs to relate to
records from tblCompanies and tblPeople. Why? Because a "payee"
(lngPayeeID) can be either a company (tblCompany.lngCompanyID) or a
person (tblPeople.lngPersonID).

I know how to relate tblPayments.lngPayeeID to a single table's field,
such as tblCompanies.lngCompanyID. I just can't figure out how to
relate it to two unlike tables (i.e., a payee can be a company or
person, which are both unrelated to each other).

Any suggestions are appreciated!
John

It would be easier for you if you had a rule that payees have to be people.
It would mean that you would have to add a person to each company you wanted
a payment from - but it would not force you to make structure changes.

If, however, you are feeling industrious then you could change your
structure so you have a table of parties which gives a unique ID to each
party (whether company or person). Then both tblCompanies and tblPeople
have a field FkPartyID(indexed no duplicates) so there is a 1-1 relationship
between the tables. In the table of payments you record the party ID for
the payee.

This idea of subclassing parties into either companies or people might suit
you, but it might be overkill for something that you could solve in a lazier
fashion. Let us know what you think.
Fletcher
Nov 12 '05 #2
Fletcher, thanks for the reply. The tables (tblPeople and tblCompanies)
must remain unrelated unforunately for me.

Your idea on creating a field/key that would be unique to both tables is
interesting...I'm not sure how I'd implement that tho. How could I
ensure the new field contained unique data without user intervention
(i.e., an autonumber field for two "joined" tables)?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
"John Kreps" <de***********@kreps.mailsnare.net> wrote in message
news:3f***********************@news.frii.net...
Fletcher, thanks for the reply. The tables (tblPeople and tblCompanies)
must remain unrelated unforunately for me.

Your idea on creating a field/key that would be unique to both tables is
interesting...I'm not sure how I'd implement that tho. How could I
ensure the new field contained unique data without user intervention
(i.e., an autonumber field for two "joined" tables)?

You could have PtyID as an autonumber, PtyName as text. When you add either
a new company or new person you first create an entry in tblParty and get an
ID. This ID is then put into either tblCompanies.FkPartyID or
tblPeople.FkPartyID before filling in the other fields for the selected
table.

I have used this idea in a database I did for a university where all
contacts got an entry in tblPersons, but students had an entry in
tblStudents with a matching PsnID which was also unique in the students
table. This made a certain amount of sense because although all people
share fields like FirstName, LastName, etc students had additional data not
relevant to other types of person. In other words students were modelled as
a sub-class of people (sub-class - what an appropriate prefix ;-)

Obviously, your situation is not quite the same and my gut feeling is that
there might be a better way. It's really hard to say without an overall
view of the database. Here are a few random thoughts:

Allocate all payments to people (Although I might guess, you haven't
actually stated why you wouldn't do this)

Not enforce referential integrity at table level. Let your interface and
coding take care of it.

Split the payments table into PeoplePayments and CompanyPayments and join
with a union query.

Perhaps you will get some input from others...

Fletcher
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: NotGiven | last post by:
Please help me understand the big picture of allowing users to upload pictures and keep them separate and tied to their record in the database. I want the whole thing automated and I'm just...
2
by: Manfred | last post by:
Hi Would like to add a new Field to Table which is 75 % (or another Percentage) higher than the Value in another Field in same Table.Is this possible with Expression or would I have to enter the...
3
by: Pasquale | last post by:
I have a database used for contact information and another for event information. As part of the event database, we would like to keep record of the people that are attending a certain event. These...
3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
5
by: lottaviano | last post by:
I am using Access 2002 and have two tables (Main and Actions) linked (in Relationships) on one field "CAL_ID" (primary key in Main Table). Main Table is a list of equipment. Actions Table lists...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.