解决“子查询返回多于1行"的解决方案.错误 [英] Solution to "subquery returns more than 1 row" error
本文介绍了解决“子查询返回多于1行"的解决方案.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询返回多行,而我想将条件设置为这些多行中的一个值的查询,所以基本上我希望子查询看起来像这样:
I have one query that returns multiple rows, and another query in which I want to set criteria to be either one of values from those multiple rows , so basicly I want the subquery to look something like this:
select *
from table
where id= (multiple row query);
multiple row query
返回多行的位置.因此,如果这些行中的值为1,2,3,那么我想将id设置为1或2或3.
Where multiple row query
returns multiple rows. So if the values from those rows are 1,2,3 then I want to set id to be 1 or 2 or 3.
推荐答案
=
.
当子查询返回的值大于1时,您将必须使用IN
:
When subquery returns more than 1 value, you will have to use IN
:
select *
from table
where id IN (multiple row query);
例如:
SELECT *
FROM Students
WHERE Marks = (SELECT MAX(Marks) FROM Students) --Subquery returns only 1 value
SELECT *
FROM Students
WHERE Marks IN
(SELECT Marks
FROM Students
ORDER BY Marks DESC
LIMIT 10) --Subquery returns 10 values
这篇关于解决“子查询返回多于1行"的解决方案.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文