我有一个名为Patient的表,其中我有
这样的列ID Disease1 Disease2 Disease3
----------
1 4 3 2
----------
2 2 5
----------
3 6
----------
4 1
这些是我从表疾病中得到的映射值,其中疾病名称就像
一样1 hypertension
2 niddm
3 allergy
4 cough
5 floo
6 vv
etc
现在我想要sql查询来选择
ID Disease1 Disease2 Disease3
----------
1 cough allergy niddm
----------
2 niddm floo
----------
3 vv
----------
4 HT
请记住,我有4,5个表映射表,我想要原始值代替所有这些表中的ID。
答案 0 :(得分:3)
您需要在表Disease
上加入表Patient
三次,因为Patient
中有三列依赖于Disease
SELECT a.ID,
b.Disease AS Disease1,
c.Disease AS Disease2,
d.Disease AS Disease3
FROM Patient a
LEFT JOIN Disease b
ON a.Disease1 = b.ID
LEFT JOIN Disease c
ON a.Disease2 = c.ID
LEFT JOIN Disease d
ON a.Disease3 = d.ID
要进一步了解联接,请访问以下链接: