[求教]双表多值select问题

山书生 2010-07-15 12:41:12
select * from tableA where caid=( select caid from tableB where wtforagent<=20) order by bgtime asc;


请教如何在Oracle实现以上效果,从表tableB中select出符合条件的caid(多个值),然后从tableB中select出对应caid的各条记录...

thx everyone ^.^
...全文
130 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
山书生 2010-07-24
  • 打赏
  • 举报
回复
谢谢各位方家达人~:)
have a nice weekend~!
xdy3008 2010-07-15
  • 打赏
  • 举报
回复

select * from tableA t where exists
( select 1 from tableB where t.caid=caid and wtforagent<=20)
order by bgtime asc;



个人喜欢用exists
rains0929 2010-07-15
  • 打赏
  • 举报
回复
赞同5楼的写法
header230 2010-07-15
  • 打赏
  • 举报
回复



select * from tableA t where exists
( select 1 from tableB where t.caid=caid and wtforagent<=20)
order by bgtime asc;



select * from tableA where caid in
( select caid from tableB where wtforagent<=20)
order by bgtime asc;




这两种都能达到你要的效果,
如果表中的数据不是很大话,两种任意选一种。
但是数据量大的话,推荐第一种。
lzbbob1985 2010-07-15
  • 打赏
  • 举报
回复
用那么麻烦吗??


select * from tableA a ,
( select caid from tableB where wtforagent<=20) b
where a.caid = b.caid order by bgtime asc;
baobeizhu100 2010-07-15
  • 打赏
  • 举报
回复

用等于的话,把caid限制成了一个值,把等于改成in就行
select * from tableA where caid in( select caid from tableB where wtforagent<=20) order by bgtime asc;
心中的彩虹 2010-07-15
  • 打赏
  • 举报
回复

select * from tableA t where exists( select 1 from tableB where t.caid=caid wtforagent<=20) order by bgtime asc;







心中的彩虹 2010-07-15
  • 打赏
  • 举报
回复

select * from tableA where caid in( select caid from tableB where wtforagent<=20) order by bgtime asc;





zhangwonderful 2010-07-15
  • 打赏
  • 举报
回复
select * from tableA a where exists ( select b.caid from tableB b where a.caid=b.caid and b.wtforagent<=20) order by bgtime asc;

17,377

社区成员

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

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