当子查询重新显示更多值时如何显示数据 [英] How to show data when sub query rerurn more vaule

查看:60
本文介绍了当子查询重新显示更多值时如何显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.



我有写查询,其中有2个子查询
1返回198行
其他人返回168,请告诉我们如何解决此问题

喊叫已删除-KH [/编辑]



I have write query which has 2 sub query
1 return 198 row
And other one return 168 so tell how to solve this problem

Shouting removed - KH[/Edit]

推荐答案

亲爱的朋友,

您可以使用Distinct或Group by或Top1.
它会为您提供帮助.但是请确保满足您的要求.
Dear Friend,

You can use Distinct or Group by or Top 1.
It will help you. But make sure that, your requirement is fulfilled.


而不是=,请使用In

我认为您的查询看起来像是
Instead of =, use In

I think your query will be looking something like
select * from employee where empid=(select empid from employee where dept='SE')




所以现在发生了什么,子查询将返回多行,但由于您提到了条件"=",所以它返回错误.

在这种情况下,您必须使用IN或存在




So now what happens, the subquery will return you more than one row but since you mentioned condition''='', it returns error.

In that case, you have to use IN or exists

select * from employee where empid in (select empid from employee where dept='SE')



如果使用!=,则不要使用.

但请注意:不使用将影响性能,使用不存在



In case if you used !=, then use not in.

But note: Not in will affect performance use not exists


这篇关于当子查询重新显示更多值时如何显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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