我有以下表格:
1. tbPatientEpisode (
EpisodeIDP
EpisodeNumber
DoctorIDF
PatientIDF
)
2. tbPatient (
PatientIDP
CitizenIDF
)
3. tbDoctor(
DoctorIDP
CitizenIDF
)
4. tbCitizen(
CitizenIDP
CitizenName
City
ContactNo
)
我想查询tbPatientEpisode表,连续获取DoctorName和PatientName,但PatientIDF和DoctorIDF指向tbCitizen。所以请帮助加入tbCitizen表两次。
答案 0 :(得分:1)
试试这个适合你,
Select pe.*, c1.CitizenName as PatientName, c2.CitizenName as DoctorName
from tbPatientEpisode pe
join tbPatient p on pe.PatientIDF = p.PatientIDP
join tbDoctor d on pe.DoctorIDF = d.DoctorIDP
join tbCitizen c1 on p.CitizenIDF = c1.CitizenIDP
join tbCitizen c2 on d.CitizenIDF = c2.CitizenIDP