两张表关联查询问题!急!! T2这张表中相同的jlbh纪录所有字段都相同?对于相同的jlbh,比如有1,2,3个,你想选择的是哪一条?为什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from T1 a ,T2 bwhere a.jlbh=b.jlbh(+) and b.jlbh is not null 楼上的不对我说清楚点比如:T1中jibh为1的只有一条T2中jibh为1有两条,如果关联查询的话,select a.jlbh from T1 a ,T2 bwhere a.jlbh=b.jlbh不用distinct 的话会列出两条jlbh相同的记录,怎样才能只列出一条? 这个是我做的例子,不知道满足你的要求吗?SQL> select * from aaa; COLA COLB---------- ---------- 111 333 222 333 222 444已用时间: 00: 00: 00.01SQL> select * from bbb;COLA COLB COLC--------- --------- ----------11 22 11111 22 22211 22 33311 33 333已用时间: 00: 00: 00.00SQL> select a.cola,a.colb from aaa a where exists (select 1 from bbb b where a.colb = b.colc); COLA COLB---------- ---------- 111 333 222 333 select t.jlbh from T1 t,T2 a where t.jlbh = a.jlbhunion select a.jlbh from T1 t,T2 a where t.jlbh = a.jlbh有点多,嘿嘿,不过能满足要求 select * from T1 a ,T2 bwhere a.jlbh(+)=b.jlbh and a.jlbh is not null应该可以了 oracle中如何查看sql的执行计划,一个sql查询结果产生的IO,B树索引查找机制是不是类似于sqlserver的书签查找 elsif内再嵌套if语句问题 3113&7445等待高手现身 先祝大家新年快乐!再来一个小问题! 总是提示无效字符 复杂的where语句 急,imp的时候,总是导入所有的表后,提示结束,但有警告! 简单但送高分! 在ORACLE中如何实现只存文件路径而不存文件? plsql把数据导入excel遇到困难 触发器的问题 想把表中id=3,且date和系统时间隔15天的记录找出
where a.jlbh=b.jlbh(+) and b.jlbh is not null
我说清楚点
比如:T1中jibh为1的只有一条
T2中jibh为1有两条,如果关联查询的话,
select a.jlbh from T1 a ,T2 b
where a.jlbh=b.jlbh
不用distinct 的话会列出两条jlbh相同的记录,怎样才能只列出一条?
---------- ----------
111 333
222 333
222 444已用时间: 00: 00: 00.01
SQL> select * from bbb;COLA COLB COLC
--------- --------- ----------
11 22 111
11 22 222
11 22 333
11 33 333已用时间: 00: 00: 00.00
SQL> select a.cola,a.colb from aaa a where exists (select 1 from bbb b where a.colb = b.colc); COLA COLB
---------- ----------
111 333
222 333
union
select a.jlbh from T1 t,T2 a where t.jlbh = a.jlbh
有点多,嘿嘿,不过能满足要求
where a.jlbh(+)=b.jlbh and a.jlbh is not null
应该可以了