microsoft access self joins
DESCRIPTION
Shows how to create a self join in Microsoft Access. A self join is a table joined to itself. This presentation uses employees reporting to their supervisor in the same table as an example.TRANSCRIPT
Self Joins 1
Microsoft Access Self Joins
Orange Coast Database AssociatesLaguna Niguel, CA [email protected] case
Factory 2000 Case
Self Joins 2
Background
A self join joins a table to itself This is useful for hierarchical
relationships Parts lists Employee relationships
(manager/supervisor) Customer referrals Etc.
This presentation shows how to create a query in Microsoft Access that joins a table to itself
Factory 2000 Case
Self Joins 3
Database Design
MgrNo is a foreign key in the employees table that refers to the table’s own primary key, EmpNo.
We will create a query that lists each employee along with their manager’s name.
Factory 2000 Case
Self Joins 4
Downloads
This database is available on Box.com.
The presentation is on Slideshare.
Factory 2000 Case
Self Joins 5
Sample Table
Below is a screenshot of the sample Employees table
Factory 2000 Case
Self Joins 6
Query Design Step 1
Add the Employees table to the query designer twice. The second time Access will give it the name Employees_1.
Factory 2000 Case
Self Joins 7
Assign Alias
Right click on the title of the 2nd Employees table and give it an alias of Managers.
Factory 2000 Case
Self Joins 8
Create Relationship
Create an outer join relationship between the two tables. This will show the employee even if they have no supervisor in the employees table (say the President).
Populate the fields to be shown.
Factory 2000 Case
Self Joins 9
Save and Run
Save the query and run it. Below are the results from our sample table.
Factory 2000 Case
Self Joins 10
Additional Considerations If desired the relationship of a table joined
to itself can be created as a permanent link using the relationship designer.
The example we used in this presentation is a one-to-many relationship (one employee reports to one manager, one manager may have several employees). Many to many relationships such as for matrix management are also possible by using a 3rd intersection table.
Factory 2000 Case
Self Joins 11
Conclusion
This presentation showed how to create a simple self join query in Access.
You should find many uses for this: reporting relationships, parts lists, customer referrals, etc.
Go to Slideshare to find related Microsoft Access presentations.
[end self joins]
Factory 2000 Case