子查询返回1行以上 [英] subquery returns more than 1 row

查看:109
本文介绍了子查询返回1行以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select 
    disease_name 
from 
    disease 
where 
    disease_id=
    (select disease_id from disease_symptom where
        disease.disease_id=disease_symptom.disease_id AND 
        symptom_id=
               (select symptom_id from symptom where symptom.symptom_id=disease_symptom.symptom_id
                AND symptom_name='fever' OR symptom_name='head ache'))

给出一个错误,子查询返回多个行.是什么原因?

Gives an error that subquery returns more than one row. what is the cause?

推荐答案

您的两个外部查询的结构使其期望从其子查询获得单个结果.但是,按照事物结构化的方式,子查询可能会返回多个结果.如果您实际上想要一个以上的结果,请按照以下方式对其进行重组:

Your two outer queries are structured to expect a single result from the their subqueries. But the way you have things structured, your subqueries might return more than one result. If you actually want more than one result, restructure it like this:

... where disease_id IN (subquery returning multiple rows...)

此外,子查询会导致性能下降,而嵌套子查询则呈指数级下降.您可能想研究使用INNER JOIN代替.

Also, subqueries is kill performance, and it's exponentially wosrse for nested subqueries. You might want to look into using INNER JOIN instead.

这篇关于子查询返回1行以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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