This might be simple one but I am finding it very difficult to work around it.
I have got 3 tables like; Employee, manager, supervisor in here manager and supervisor is the specialization of the table employee. Now I have got another table say Project which should have 1 manager and 3 supervisor.
How do I put this in my mysql database?
As Employee has Employeeid, name, position and manager will have employeeid as pk and fk sme with supervisor which will have employeeid as pk and fk. How do I put the data in manager and supervisor table? Do I use a view?
How would mysql know which is manager and which is supervisor?
How to connect your tables:
You can make an additional table
ProjectMemberwith the following columns:Where role can be ‘manager’ or ‘supervisor’.
So, if these are your
Employees:And this is your
Project:Then the
ProjectMembertable can have the following rows:To get the names of all members of Project X you can then use the following query:
This will return:
Adding specializations
If there is any specific data for a
Manageror aSupervisoras specializations ofEmployee, then you can retrieve the additional data as follows.Suppose Mark is a
Manager, then this can be a row inManager:EDIT: To store a
Manager, you first store anEmployeeand get its (probably generated)employeeId. How to get a generated id depends on the database system you are using (see this on MySQL). Then you store a row inManagerwith that sameemployeeId.To get this additional information, while you do not really know who is in the
Managertable on beforehand, you can use aLEFT JOINto retrieve data from optional additional tables (they may or may not be there, but you still want to get the basic queried rows):This will return: