I am having some trouble understanding how to implement many-to-many relationships. I know conceptually that this calls for an intermediary table with a one-to-many relationship with each of the other two tables. However, I can
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Many-to-many relationships (XP, 2000)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Many-to-many relationships (XP, 2000)
- This topic has 13 replies, 3 voices, and was last updated 15 years, 2 months ago.
AuthorTopicWSDon_Sadler
AskWoody LoungerApril 14, 2004 at 1:42 pm #403643Viewing 2 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerApril 14, 2004 at 2:06 pm #814574Trying to do this is complicated. Let’s take a simpler example first: two tables Table A and Table B with a many-to-many relationship. This is implemented by creating an intermediary table Table D with a composite primary key consisting of the combination of two number (long integer) fields that are linked to the primary keys in Table A and Table B.
Table A has a one-to-many relationship with Table D, and Table B also has a one-to-many relationship with Table D. Together, these constitute a many-to-many relationship between Table A and Table B.
We don’t create a form based on Table A with a subform based on Table B.
Depending on the perspective from which you want to look at the data, you would create either a main form based on Table A with a subform based on Table D (or on a query that includes Table D and Table
or a main form based on Table B with a subform based on Table D (or on a query that includes Table D and Table A.)
An example may make things clearer:
Table A = students, with primary key StudentID
Table B = courses, with primary key CourseID
Table D = participation, with a primary key consisting of the combination of StudentID and CourseID.Each record in Table D represents a student participating in a course.
There can be many records with the same StudentID (but all different CourseID’s) – they tell us which courses a particular student attends.
There can be many records with the same CourseID (but all different StudentID’s) – they tell us which students attend a particular course.
You could have two forms:
1. A form based on the students table, with a subform based on the participation table, displaying the courses attended by a student. Main form and subform are linked by StudentID.
2. A form based on the courses table, with a subform based on the participation table, displaying the students attending a course. Main form and subform are linked by CourseID. -
WSjohnhutchison
AskWoody LoungerApril 15, 2004 at 6:40 am #815296Hans
You suggest that the intermediate table have a composite primary key, consisiting of the two foreign keys.
I often want to allow for the possibility of multiple entries in the intemediate table for the same pair of values in the the Main tables. For example, a patron may borrow a book more than once, or a student undertake a course many times (perhaps until they pass!). Your design does not allow this, so instead I just create another autonumber field in the intermediate table and set this as the key.
Is there any downside to doing this?
-
WSHansV
AskWoody LoungerApril 15, 2004 at 6:51 am #815302John,
I would decide that on a case-to-case basis. I might create yet another table with a one-to-many relationship to the intermediary table, or I might use the keys from the main tables plus a sequential number, or an autonumber (your approach.) Sometimes a complete normalization is just too cumbersome.
-
WSHansV
AskWoody LoungerApril 15, 2004 at 6:51 am #815303John,
I would decide that on a case-to-case basis. I might create yet another table with a one-to-many relationship to the intermediary table, or I might use the keys from the main tables plus a sequential number, or an autonumber (your approach.) Sometimes a complete normalization is just too cumbersome.
-
-
WSjohnhutchison
AskWoody LoungerApril 15, 2004 at 6:40 am #815297Hans
You suggest that the intermediate table have a composite primary key, consisiting of the two foreign keys.
I often want to allow for the possibility of multiple entries in the intemediate table for the same pair of values in the the Main tables. For example, a patron may borrow a book more than once, or a student undertake a course many times (perhaps until they pass!). Your design does not allow this, so instead I just create another autonumber field in the intermediate table and set this as the key.
Is there any downside to doing this?
-
WSDon_Sadler
AskWoody LoungerApril 16, 2004 at 2:16 pm #815873 -
WSHansV
AskWoody LoungerApril 16, 2004 at 2:36 pm #815881General recommendations:
– Turn off “Track Name AutoCorrect Info” in the General tab of Tools | Options… in each database you create.
– Set the Subdatasheet Name property of all tables to [None].
– Avoid creating duplicate indexes; Courses, for example, had two indexes on CourseID.I have created the subforms for you and placed them on the main forms. They are very simple continuous subforms, with a combo box to let the user select a course or student. See attached.
-
WSDon_Sadler
AskWoody LoungerOctober 17, 2009 at 1:20 pm #1181936I very much appreciate the sample DB you attached. I have studied it and it will launch me on a total redesign of my DB. However, as I look at the forms & subforms, I don’t see where the information in the subforms come from. For example, in looking the Courses form and the subform (sbfStudents), I cannot find how the students’ names appears in the subform. The subform has but one field and that is the StudentID field. I see that it uses the query (qryStudents) as the row source but how is the student name retrieved? The query has two columns but the subform field is bound to column 1. I changed it to ‘0’ to see what effect, if any, and it had no effect.
Thanks you.
General recommendations:
– Turn off “Track Name AutoCorrect Info” in the General tab of Tools | Options… in each database you create.
– Set the Subdatasheet Name property of all tables to [None].
– Avoid creating duplicate indexes; Courses, for example, had two indexes on CourseID.I have created the subforms for you and placed them on the main forms. They are very simple continuous subforms, with a combo box to let the user select a course or student. See attached.
-
WSHansV
AskWoody LoungerOctober 17, 2009 at 3:44 pm #1181947The combo box StudentID has the query qryStudents as Row Source. This query has 2 fields:
– The first field is StudentID.
– The second field is a calculated field that concatenates the last and first names of the student, separated by a comma and a space:SName: [LName] & “, ” & [FName]
The combo box has Column Count = 2 (corresponding to the two fields/columns in the query) and Column Widths = 0″;1″.
This means that the first column has width 0″, which effectively hides it, while the second column has width 1″.
The combo box displays the first non-hidden column, i.e. the column corresponding to the student name SName.
Since the Bound Column = 1, the value stored by the combo box is not the student name displayed in the second column, but the value of the hidden first column, which corresponds to StudentID.
-
-
-
WSHansV
AskWoody LoungerApril 16, 2004 at 2:36 pm #815882General recommendations:
– Turn off “Track Name AutoCorrect Info” in the General tab of Tools | Options… in each database you create.
– Set the Subdatasheet Name property of all tables to [None].
– Avoid creating duplicate indexes; Courses, for example, had two indexes on CourseID.I have created the subforms for you and placed them on the main forms. They are very simple continuous subforms, with a combo box to let the user select a course or student. See attached.
-
-
WSDon_Sadler
AskWoody LoungerApril 16, 2004 at 2:16 pm #815874
-
-
WSHansV
AskWoody LoungerApril 14, 2004 at 2:06 pm #814575Trying to do this is complicated. Let’s take a simpler example first: two tables Table A and Table B with a many-to-many relationship. This is implemented by creating an intermediary table Table D with a composite primary key consisting of the combination of two number (long integer) fields that are linked to the primary keys in Table A and Table B.
Table A has a one-to-many relationship with Table D, and Table B also has a one-to-many relationship with Table D. Together, these constitute a many-to-many relationship between Table A and Table B.
We don’t create a form based on Table A with a subform based on Table B.
Depending on the perspective from which you want to look at the data, you would create either a main form based on Table A with a subform based on Table D (or on a query that includes Table D and Table
or a main form based on Table B with a subform based on Table D (or on a query that includes Table D and Table A.)
An example may make things clearer:
Table A = students, with primary key StudentID
Table B = courses, with primary key CourseID
Table D = participation, with a primary key consisting of the combination of StudentID and CourseID.Each record in Table D represents a student participating in a course.
There can be many records with the same StudentID (but all different CourseID’s) – they tell us which courses a particular student attends.
There can be many records with the same CourseID (but all different StudentID’s) – they tell us which students attend a particular course.
You could have two forms:
1. A form based on the students table, with a subform based on the participation table, displaying the courses attended by a student. Main form and subform are linked by StudentID.
2. A form based on the courses table, with a subform based on the participation table, displaying the students attending a course. Main form and subform are linked by CourseID. -
WSDon_Sadler
AskWoody Lounger
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
A Funny Thing Happened on the Way to the Forum
by
bbearren
11 minutes ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
5 hours, 53 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
4 hours, 53 minutes ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
3 hours, 17 minutes ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
4 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
18 hours, 41 minutes ago -
Hackers are using two-factor authentication to infect you
by
B. Livingston
12 hours, 42 minutes ago -
23 and you
by
Max Stul Oppenheimer
58 minutes ago -
April’s deluge of patches
by
Susan Bradley
5 hours, 9 minutes ago -
Windows 11 Windows Updater question
by
Tex265
10 hours, 56 minutes ago -
Key, Key, my kingdom for a Key!
by
RetiredGeek
1 day, 9 hours ago -
Registry Patches for Windows 10
by
Drcard:))
1 day, 14 hours ago -
Cannot get line length to NOT wrap in Outlining in Word 365
by
CWBillow
20 hours, 54 minutes ago -
DDU (Display Driver Uninstaller) updates
by
Alex5723
6 hours, 13 minutes ago -
Align objects on a OneNote page
by
CWBillow
1 day, 19 hours ago -
OneNote Send To button?
by
CWBillow
1 day, 20 hours ago -
WU help needed with “Some settings are managed by your organization”
by
Peobody
2 days, 5 hours ago -
No Newsletters since 27 January
by
rog7
9 hours, 40 minutes ago -
Linux Mint Debian Edition 7 gets OEM support, death of Ubuntu-based Mint ?
by
Alex5723
1 day, 5 hours ago -
Windows Update “Areca Technology Corporation – System – 6.20.0.41”
by
Bruce
1 day, 4 hours ago -
Google One Storage Questions
by
LHiggins
12 hours, 16 minutes ago -
Button Missing for Automatic Apps Updates
by
pmcjr6142
19 hours, 31 minutes ago -
Ancient SSD thinks it’s new
by
WSila
1 day, 10 hours ago -
Washington State lab testing provider exposed health data of 1.6 million people
by
Nibbled To Death By Ducks
2 days, 19 hours ago -
WinRE KB5057589 fake out
by
Susan Bradley
6 hours, 29 minutes ago -
The April 2025 Windows RE update might show as unsuccessful in Windows Update
by
Susan Bradley
2 days, 3 hours ago -
Firefox 137
by
Charlie
6 hours, 27 minutes ago -
Whisky, a popular Wine frontend for Mac gamers, is no more
by
Alex5723
3 days, 8 hours ago -
Windows 11 Insider Preview build 26120.3863 (24H2) released to BETA
by
joep517
3 days, 8 hours ago -
Windows 11 Insider Preview build 26200.5551 released to DEV
by
joep517
3 days, 8 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.