Zack
Zack

Reputation: 121

Merging datasheet and subdatasheet with a query in access

I have an access table that has its own information as well as a subdatasheet that was linked to it using child/master fields. For each record in the table, there is one record in the subdatasheet. I was wondering if one can give me code for a query that would put all of this into one table.

Upvotes: 0

Views: 1907

Answers (1)

XIVSolutions
XIVSolutions

Reputation: 4502

If you are certain of the one-to-one relationship, then you can simply JOIN on the Foreign key relationship between the "Master" and "Child" tables:

SELECT m.PKID, m.MasterField1, m.MasterField2, c.ChildField1, c.ChildField2
FROM ChildTable AS c INNER JOIN MasterTable AS m ON c.ClientID = m.ClientID;

If you are really intending to merge these into a new table, then open the Access Query Editor, select SQL View from the View menu, and paste the above sample into the SQL view. Then swap your table names, and column names for those above (adding m.MasterField3, 4, . . . c.ChildField3, 4, etc . . .).

Then select Make Table Query from the Query type menu. Type a unique name for your new table, and Run the query.

Upvotes: 1

Related Questions