select查询出错single-row subquery returns more than one row

superquestions 2010-03-20 09:52:42
出错原因是
select x from tablea where column=(select b from tableb)
而子查询返回的结果不止一条

按这个情况查询,有没有办法解决不出错又能查询到?
...全文
713 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ORACLE800 2010-03-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 adebayor 的回复:]
select x from tablea where column in(select b from tableb);
[/Quote]
支持.
xiaoheixiaobai 2010-03-22
  • 打赏
  • 举报
回复
1,select x from tablea where column=any(select b from tableb)

2,select x from tablea where column in(select b from tableb);

3,select x from tablea a where exists
(select 1 from tableb b
where b.b=a.column
);
这三种方法,习惯用第三种,不知道具体的执行效率是怎么样的,请高人指教。
hebo2005 2010-03-22
  • 打赏
  • 举报
回复
几种方法,效率各不同

如2楼
select x from tablea where column in(select b from tableb);

还可以用EXISTS,大部分情况比IN的效率高
select x from tablea a where exists
(select 1 from tableb b
where b.b=a.column
);
Raul_Gonzalez 2010-03-22
  • 打赏
  • 举报
回复
SELECT a.x
FROM tablea a, tableb b
WHERE a.COLUMN = b.b
huangyunzeng2008 2010-03-22
  • 打赏
  • 举报
回复
select x from tablea where column=(select b from tableb where rownum=1)
wildoracle 2010-03-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 suiziguo 的回复:]
select x from tablea where column=any(select b from tableb)
[/Quote]
可以实现
liugh_dba 2010-03-20
  • 打赏
  • 举报
回复
一般 “1 = N”时就会报这个错,看你的实际用途,是在一个范围内的话可以采用上述方法,这种错误也经常在DML 语句中出现!
Adebayor 2010-03-20
  • 打赏
  • 举报
回复
select x from tablea where column in(select b from tableb);
suiziguo 2010-03-20
  • 打赏
  • 举报
回复
select x from tablea where column=any(select b from tableb)

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧