如何通过mysql中的join语句从三个表中获取数据 [英] how to get data from three tables by a join statement in mysql

查看:84
本文介绍了如何通过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 

这篇关于如何通过mysql中的join语句从三个表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆