Josh
A typical approach to a "self join" is the boss and employee.
EmployeeTbl
EmployeeID - primary key
EmployeeName
SuerpvisorID - foreign key, but points to the EmployeeID
A person is their own boss would use their own employee ID as their supervisor ID.
But I do not think this is what you are looking for. Can we explore some design issues for a moment??
ContactTbl
ContactID - primary key
ContactName
etc
BuildingTbl
BuildingID - primary key
RoomTbl
RoomID - primary key
BuildingID - foreign key to BuildingTbl
BedTbl
BedID - primay key
RoomID - foreign key to RoomTbl
But how do you confirm a registration? There are various solutions. Here is one to consider... Create a registration table.
RegistrationTbl
RegID - primary key
ContactID - foreign key to contact table
PartnerID - foreign key to contact table
BedID - foreign key to BedTbl
RoomID - foreign key to RoomTbl
With this approach...
- contact reserves a bed
- contact + partner reserves a room
The relational savy guys will note that this design kind of breaks the rules of normalization. On the registration table, the RoomID can be used to retrieve the RoomID. However, this is the only way I can see to easily to have a group book a room.
A limitation to this design is if a group of people want to book a dormatory situation. In this case, you would have create a separate table, say PartnerTbl. Same idea, but a little more complicated.
Another limitation is what do you do if a group makes the reigstration? In this case, I suggest you treat each member within the group as a registrant.
A couple of things on the registration table.
- If you make the index for ContactID unique, no duplicates, you will prevent a person from being registered twice
- If you make the index for the RoomID unique, no nulls, you will prevent a bed from being booked twice. But this may cause problems if you have a registrant that you don't want to assign to a room until you research the situation further - special needs (handicap access, room mates, etc). If you make the RoomID unique, no nulls, then you have to book the bed.
Some logic would have to be developed to handle all this, but I think the design would work.
This design does not handle payment, course schedules (if structured), but it does address your specific question.
Richard
-