-2

I'm a beginner in development. I'm breaking my head and I'm confused as to the problem below.

an employee can be a programmer or analyst

Programmer

  • name
  • sex
  • age
  • programming language

Analyst

  • name
  • sex
  • age
  • Project
  • 2
    What is your question? – philipxy Dec 20 '18 at 11:27
  • Hi. This is a faq. Please always google error messages & many clear, concise & specific versions/phrasings of your question/problem/goal with & without your particular strings/names & 'site:stackoverflow.com' & tags & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using 1 variant search as title & keywords for tags. See the downvote arrow mouseover text. When you do have a non-duplicate code question to post please read & act on [mcve]. – philipxy Dec 20 '18 at 11:29

2 Answers2

1

You can have a row associated with each Employee that stores the Foreign key of whether the employee is an Analyst or a Programmer.

E.g.

Employee
 - id
 - Name
 - Sex
 - Age
 - Type_Id

Types
 - id
 - Type

Example Data:

Types
 - 1, Programmer
 - 2, Analyst

Employee
 - 1, "Sid", "Male", 25, 1
 - 2, "Sandra", "Female", 28, 2

With this approach, if more roles are added in future, you can just add it to master table Types and refer it from Employee Table.

Sid
  • 4,893
  • 14
  • 55
  • 110
0

Use foreign keys.

So if you have an Employee table, you can connect them likes this:

Employee

id
name
sex
age

Programmer

employeeId

Analyst

employeeId

EmployeeId will refer to a row inside the Employee table with a matching id column

Roi
  • 983
  • 9
  • 17