更高效的查询来获取特定身体部位的所有症状?

时间:2015-05-19 13:53:06

标签: mysql

是否有更短/更有效的查询来替换它?

SELECT s_name 
FROM symptom, bodypart_symptoms, bodypart 
WHERE bodypart_symptoms.bp_id = bodypart.bp_id 
AND bodypart.bp_name = '$bodypart' 
AND symptom.s_id = bodypart_symptoms.s_id

表格结构:

bodypart: bp_id,bp_name

bodypart_symptoms: bp_id,s_id

疾病: d_id,d_name

disease_symptoms: d_id,s_id

症状: s_id,s_name

2 个答案:

答案 0 :(得分:2)

SELECT s_name 
FROM bodypart_symptoms
LEFT JOIN bodypart 
ON bodypart_symptoms.bp_id = bodypart.bp_id 
  AND bodypart.bp_name = '$bodypart' 
LEFT JOIN symptom
ON symptom.s_id = bodypart_symptoms.s_id

答案 1 :(得分:1)

您应该像这样使用INNER JOIN

SELECT s_name
FROM symptom
INNER JOIN bodypart_simptoms
ON symptom.s_id = bodypart_symptoms.s_id
INNER JOIN bodypart 
ON bodypart_symptoms.bp_id = bodypart.bp_id 
WHERE bodypart.bp_name = '$bodypart'