如何通过mysql中的join语句从三个表中获取数据

问题描述:

在我的应用程序中,我有三个表,即预订患者子单位,我需要从预订表中获取 Patient_id并在患者表中查询患者数据 相同时间 ,我需要从预订表中获取 sub_unit_id,并从sub_unit中查询sub_unit名称表 ...我需要将所有这些数据按
Patient_id,sub_unit_name,Patient_name,address之类的顺序放入一个数组中,并将其传递给Codeigniter表类以绘制表。

In my application i have three tables, reservation, patient and sub_unit, i need to take the patient_id from reservation table and query the patient table for patient data,same time i need to take the sub_unit_id from the reservation table and query the sub_unit name from the sub_unit table... i need to put all this data in to an one array in the sequence like patient_id, sub_unit_name, patient_name, address and pass it to the Codeigniter table class to draw a table.

如何同时查询三个表以查询此数据?你们可以帮我吗?

How can I query three tables in the same time to query out this data? can you guys help me out?

Select r.patient_id, s.sub_unit_name, p.patient_name, p.address 
from reservation r, sub_unit s, patient p 
where r.patient_id = p.patient_id and r.sub_unit_id = s.sub_unit_id