SQL查询连接不起作用
问题描述:
我有三个表。 tooth,toothchart and tblpatient
以下是column
名SQL查询连接不起作用
tooth-Tid,toothName
toothchart-patientId,stage, TeethCode,note
tblpatient-patientId,fname
我想从“tooth
”表和“teethchart
”表中的所有值从“tblpatient
”表给定的病人的价值观,但我查询不把所有的tooth
表的值。
这是我的查询。
SELECT tooth.*,teethchart.*,fname
FROM tooth
LEFT JOIN teethchart ON tooth.toothName = teethchart.TeethCode
left join tblpatient on teethchart.patientId=tblpatient.patientId
where teethchart.patientId = 'P0001'
任何人都可以帮助我解决这个问题吗?
答
下面的查询将会把所有的项目从牙齿图表,只有那些从teethchart和tblpatient
SELECT t.*, p.fname, tc.*
From tooth t
left join teethchart tc on t.toothName = tc.TeethCode
left join tblpatient p on tc.patientId = p.patientId
and p.patientId = 'P0001';
匹配