This document discusses self joins in Microsoft Access. A self join joins a table to itself to show hierarchical relationships like parts lists or employee managers. The presentation shows how to create a query that lists employees along with their managers by joining the Employees table to itself. It demonstrates adding the Employees table twice to the query designer, giving one an alias of "Managers", and creating an outer join between the tables on the EmpNo and MgrNo fields to return results even if an employee has no manager. The results of the sample query on the provided Employees table are shown.
How to Troubleshoot Apps for the Modern Connected Worker
Microsoft access self joins
1. Orange Coast Database Associates
Laguna Niguel, CA 92677
Slides.1@dhdursoassociates.com
Factory2000 case
Factory 2000 Case
Self Joins
1
2.
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
2
3.
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
3
4.
This database is available on Box.com.
The presentation is on Slideshare.
Factory 2000 Case
Self Joins
4
5.
Below is a screenshot of the sample
Employees table
Factory 2000 Case
Self Joins
5
6.
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
6
7.
Right click on the title of the 2nd Employees table
and give it an alias of Managers.
Factory 2000 Case
Self Joins
7
8.
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
8
9.
Save the query and run it. Below are the
results from our sample table.
Factory 2000 Case
Self Joins
9
10.
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
10
11.
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
Self Joins
11