473,387 Members | 1,464 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,387 software developers and data experts.

Repost: Connecting a table to itself?

I posted this message earlier, got a reply to google for a previous
reply, which I couldn't find, so here I am again.

I've run across another situation in Access I just don't know how to
handle. I have a database of employees in our group. I have a series on

linked tables with location, cubicle, computer, etc. All that is fine
(well, since I got help here with it, it's fine!). I want to show who
each person's supervisor is. I could put in a separate list of
supervisors, most of whom would also be in the employees list. But
doesn't it make more sense to put in a boolean field in the employee
table for supervisor? Then extract a separate table for just
supervisors and relevant information? And link that table back to the
employee table? But then what happens when a new supervisor is named?
The supervisor table would have to be deleted, along with the link, for

the query to re-create the supervisor table. Somehow, what doesn't
sound right to me.
The other problem it creates is the the head of the department's
supervisor is not an employee of the department. So I'd either have to
leave the dpt. supervisor with no supervisor, or add the dpt's
supervisor's supervisor as an employee, which isn't really true. Is
this confusing you as much as it is me?
I'm sure many of you have resolved these difficulties eons ago. So what

are the best solution(s) for this situation?

Nov 13 '05 #1
7 1588
I want to show who each person's supervisor is.
table structure is something like this...

CREATE TABLE employee (
EmployeeID LONG NOT NULL,
FirstName TEXT(20) NOT NULL,
LastName TEXT(20) NOT NULL,
....
SupervisorID LONG,

FOREIGN KEY (SupervisorID) REFERENCES employee(employeeID));

in your form, you can make SupervisorID a combobox - you know the drill
- show employee.FirstName & " " & employee.LastName.

The only catch is that you'll have to either start with the data from
the top of the hierarchy (most senior staff first) and work your way
down to the least senior employees.

then in the OnCurrent event of your form, you may have to requery the
supervisor combobox.

Hope this gets you started

Nov 13 '05 #2
I want to show who each person's supervisor is.
table structure is something like this...

CREATE TABLE employee (
EmployeeID LONG NOT NULL,
FirstName TEXT(20) NOT NULL,
LastName TEXT(20) NOT NULL,
....
SupervisorID LONG,

FOREIGN KEY (SupervisorID) REFERENCES employee(employeeID));

in your form, you can make SupervisorID a combobox - you know the drill
- show employee.FirstName & " " & employee.LastName.

The only catch is that you'll have to either start with the data from
the top of the hierarchy (most senior staff first) and work your way
down to the least senior employees.

then in the OnCurrent event of your form, you may have to requery the
supervisor combobox.

Hope this gets you started

Nov 13 '05 #3

pi********@hotmail.com wrote:
I want to show who each person's supervisor is.
table structure is something like this...

CREATE TABLE employee (
EmployeeID LONG NOT NULL,
FirstName TEXT(20) NOT NULL,
LastName TEXT(20) NOT NULL,
...
SupervisorID LONG,

FOREIGN KEY (SupervisorID) REFERENCES employee(employeeID));

in your form, you can make SupervisorID a combobox - you know the drill
- show employee.FirstName & " " & employee.LastName.

The only catch is that you'll have to either start with the data from
the top of the hierarchy (most senior staff first) and work your way
down to the least senior employees.
then in the OnCurrent event of your form, you may have to requery the
supervisor combobox.

Hope this gets you started


pietlin, thanks for your reply. I would have liked to reply sooner, but
this particular project is not my highest priority.
I should have stated that I am a newbie to Access and not at all
familiar with how it works, so, no, I don't "know the drill". My
questions are very basic. I did do some research in Prague's book and
in this NG before posting my reply. You show some of the fields as "Not
Null". I looked for this a number of places, but only found anything in
reference to filters and VBA, not tables. I'm guessing that this would
be the same as "Required" in the row characteristics. Is that correct?
I couldn't find any other fields where "Not null" seemed to apply.

You also had:
SupervisorID LONG,

I'm guessing this is another field in the separate table(Supervisor
Table) from the Employee table and would be a key. Is that correct?

And then:
FOREIGN KEY (SupervisorID) REFERENCES employee(employeeID))
Does this mean that Supervisor ID is a field in the employee table and
is linked 1:many with the Supervisor table?

Thanks for your help.

Nov 13 '05 #4
Okay, I'll try it in English this time =) I'm assuming the simplest
solution to this problem.

Essentially what you have is Employee (in supervisor role) supervises
another employee (who may or may not be a supervisor. If you diagram
this (a good thing to learn how to do, because it makes thinking
through your design a lot easier), you have something like this:
[Employee]----(1,M)----<supervises>---(1,1)---[Employee]
(aka "Supervisor" or "Manager")

In English:
A supervisor or manager may supervise one or more Employees.
Each employee has a supervisor.

Okay, so essentially what we have is a self-join. Employee supervises
another Employee. So if each employee has only one supervisor, we can
model this by keeping the "supervises" fact in the Employee table. So
we just put the "SupervisorID" in the Employee table, and then we can
join the table to itself in a query (by adding another copy and
aliasing it.) Something like...

qryShowEmployeeAndSupervisor

SELECT Supervisor.EmployeeID, Supervisor.FirstName,
Supervisor.lastName, tblEmployee.EmployeeID, tblEmployee.FirstName,
tblEmployee.lastName
FROM tblEmployee AS Supervisor RIGHT JOIN tblEmployee ON
Supervisor.EmployeeID = tblEmployee.SupervisorID;

Right Join is so that I can see all employees, whether or not they have
a supervisor.

Nope. SupervisorID is a field in the employee table. You're just
adding the same table to the query twice and then renaming one
"manager" and leaving the other "employee". then since all managers
are employees, we can just store the employee ID of the managing
employee in the ManagerID field. And we're sorted.

Nov 13 '05 #5
It seems like it would be much easier *not* to assume that your employees
belong to one department (yours). If you go this route, your Employees table
must include a Department ID field for each employee (and you probably also
want a Departments table). Granted, it seems as if this information is
redundant in every case except for the supervisor of your department head
(who actually is not a member of your department) but I think that that
exception justifies the design. Now your Employees table can be keyed by
Employee ID and you can include a Supervisor ID field (which of course would
be someone's Employee ID). After this it seems that your other problems
disappear. Or am I missing something?

Btw, you can limit your Departments table to two departments: yours, and the
department of your department head's supervisor.

"davegb" <da****@safebrowse.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I posted this message earlier, got a reply to google for a previous
reply, which I couldn't find, so here I am again.

I've run across another situation in Access I just don't know how to
handle. I have a database of employees in our group. I have a series on

linked tables with location, cubicle, computer, etc. All that is fine
(well, since I got help here with it, it's fine!). I want to show who
each person's supervisor is. I could put in a separate list of
supervisors, most of whom would also be in the employees list. But
doesn't it make more sense to put in a boolean field in the employee
table for supervisor? Then extract a separate table for just
supervisors and relevant information? And link that table back to the
employee table? But then what happens when a new supervisor is named?
The supervisor table would have to be deleted, along with the link, for

the query to re-create the supervisor table. Somehow, what doesn't
sound right to me.
The other problem it creates is the the head of the department's
supervisor is not an employee of the department. So I'd either have to
leave the dpt. supervisor with no supervisor, or add the dpt's
supervisor's supervisor as an employee, which isn't really true. Is
this confusing you as much as it is me?
I'm sure many of you have resolved these difficulties eons ago. So what

are the best solution(s) for this situation?

Nov 13 '05 #6

pi********@hotmail.com wrote:
Okay, I'll try it in English this time =) I'm assuming the simplest
solution to this problem.

Essentially what you have is Employee (in supervisor role) supervises
another employee (who may or may not be a supervisor. If you diagram
this (a good thing to learn how to do, because it makes thinking
through your design a lot easier), you have something like this:
[Employee]----(1,M)----<supervises>---(1,1)---[Employee]
(aka "Supervisor" or "Manager")

In English:
A supervisor or manager may supervise one or more Employees.
Each employee has a supervisor.

Okay, so essentially what we have is a self-join. Employee supervises
another Employee. So if each employee has only one supervisor, we can
model this by keeping the "supervises" fact in the Employee table. So
we just put the "SupervisorID" in the Employee table, and then we can
join the table to itself in a query (by adding another copy and
aliasing it.) Something like...

qryShowEmployeeAndSupervisor

SELECT Supervisor.EmployeeID, Supervisor.FirstName,
Supervisor.lastName, tblEmployee.EmployeeID, tblEmployee.FirstName,
tblEmployee.lastName
FROM tblEmployee AS Supervisor RIGHT JOIN tblEmployee ON
Supervisor.EmployeeID = tblEmployee.SupervisorID;

Right Join is so that I can see all employees, whether or not they have
a supervisor.

Nope. SupervisorID is a field in the employee table. You're just
adding the same table to the query twice and then renaming one
"manager" and leaving the other "employee". then since all managers
are employees, we can just store the employee ID of the managing
employee in the ManagerID field. And we're sorted.


Pietlin,
Thanks for the reply and the simplification. It's starting to make
sense, a little at a time.
I added a new number field to the Employee table named SupervisorID. I
then created a query using 2 Employee tables with a join between them,
EmployeeID to SupervisorID (right join is option 2, correct?). So far
so good.
So now do I just copy the Supervisor's EmpID and paste it into the
SupervisorID field to make the assigments? That only allows me to show
one employee per supervisor. How do I show all the employees under a
given supervisor to show?

Nov 13 '05 #7

davegb wrote:
pi********@hotmail.com wrote:
Okay, I'll try it in English this time =) I'm assuming the simplest
solution to this problem.

Essentially what you have is Employee (in supervisor role) supervises
another employee (who may or may not be a supervisor. If you diagram
this (a good thing to learn how to do, because it makes thinking
through your design a lot easier), you have something like this:
[Employee]----(1,M)----<supervises>---(1,1)---[Employee]
(aka "Supervisor" or "Manager")

In English:
A supervisor or manager may supervise one or more Employees.
Each employee has a supervisor.

Okay, so essentially what we have is a self-join. Employee supervises
another Employee. So if each employee has only one supervisor, we can
model this by keeping the "supervises" fact in the Employee table. So
we just put the "SupervisorID" in the Employee table, and then we can
join the table to itself in a query (by adding another copy and
aliasing it.) Something like...

qryShowEmployeeAndSupervisor

SELECT Supervisor.EmployeeID, Supervisor.FirstName,
Supervisor.lastName, tblEmployee.EmployeeID, tblEmployee.FirstName,
tblEmployee.lastName
FROM tblEmployee AS Supervisor RIGHT JOIN tblEmployee ON
Supervisor.EmployeeID = tblEmployee.SupervisorID;

Right Join is so that I can see all employees, whether or not they have
a supervisor.

Nope. SupervisorID is a field in the employee table. You're just
adding the same table to the query twice and then renaming one
"manager" and leaving the other "employee". then since all managers
are employees, we can just store the employee ID of the managing
employee in the ManagerID field. And we're sorted.


Pietlin,
Thanks for the reply and the simplification. It's starting to make
sense, a little at a time.
I added a new number field to the Employee table named SupervisorID. I
then created a query using 2 Employee tables with a join between them,
EmployeeID to SupervisorID (right join is option 2, correct?). So far
so good.
So now do I just copy the Supervisor's EmpID and paste it into the
SupervisorID field to make the assigments? That only allows me to show
one employee per supervisor. How do I show all the employees under a
given supervisor to show?


I redid all this and reversed the tables so the employee info was in
the columns to the left and the supervisor was to the right. At least
that way I can see each employee's supervisor, although the table is
clunky and hard to interpret at best. Any ideas on how to make it more
readable?

Nov 13 '05 #8

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

Similar topics

1
by: jelle | last post by:
Hi, I'm using win32com.client.GetObject(Class='Rhino3.Application') to connect to an existing COM server. However when doing so: Traceback (most recent call last): File "<input>", line 1, in...
7
by: Stan Brown | last post by:
I'm sorry, I should have mentioned that I'm running Mozilla 1.4 on Win 98 and my window is about 800 pixels wide. If any of that matters. The rest of this is what I posted a few minutes ago. ...
4
by: arran.pearce | last post by:
Hi, I am using .NET 2 (beta2) and are having problems with using a SqlConnection. I have created a test application that opens a sql connections, gets some basic data and then closes the...
0
by: davegb | last post by:
I posted this message earlier, got a reply to google for a previous reply, which I couldn't find, so here I am again. I've run across another situation in Access I just don't know how to handle....
3
by: Jeremy Ames | last post by:
Can someone please help with this? Unfortunately, that did not work. "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message...
5
by: Adrian Parker | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
2
by: Lincoln Yeoh | last post by:
Sorry for the repost. Just wondering if anyone has a workaround for 7.4? At 11:25 AM 1/27/2004 -0500, Tom Lane wrote: >Martijn van Oosterhout <kleptog@svana.org> writes: > > I'm afraid I'll have...
12
by: Jack | last post by:
Since, I have not got some desired advise, I am reposting this for some asnwer/valuable suggestion. Thanks. THE FOLLOWING IS A PART OF CODE FROM A ASP PAGE <% sql01 = "SELECT COUNT(*) AS...
2
jhardman
by: jhardman | last post by:
I keep getting connection errors that appear to me to relate to user permissions. I tried connecting with DSN from both a classic ASP page using VBScript, and from a .NET web service using C#,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.