Question

I am trying to create a table that shows treatment information about patients (though I just wondered if would be better as a query) at a fictional hospital. The idea is that one row of this could be used to print an information sheet for the attending nurse(s).

I would like to make the attending_doctor column contain the name that corresponds with the employee_id.

|Patient_ID|Employee_ID|Attending_Doctor|Condition|Treatment|future_surgery| 

Would appreciate any help. Thank you!

Was it helpful?

Solution

Just use a join in your query rather than have the employee name in 2 tables (which would mean updating in more than one location if they change name etc). For the sake of an example, this also gets the patients name from a 3rd table named patients.

eg

SELECT table1.*, employees.name, patients.name 
  FROM table1
  LEFT JOIN employees ON employees.id = table1.employeeId
  LEFT JOIN patients ON patients.id = table1.patientsId

OTHER TIPS

Don't use directly this table, but build a view that contains the data you need. Then you can get the data from the view like it was a table.

Basically what you need is to have data in three tables. One table for patients, one table for for employees and one for the reports. Table with reports should contain only the employee_ID. Then you can either build a direct query over these three tables or build a view that will hide the complicated query.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top