【发布时间】:2017-03-20 17:05:33
【问题描述】:
我想查询多个表,但只返回唯一记录。
我当前的查询:
select
a.*,
b.*,
c.*
from c_inv a
inner join p_master b
on a.c_code = b.c_code
and a.p_code = b.p_code
left join c_proj c
on b.c_code = c.c_code
and b.p_code = c.p_code
where a.c_code = 'AA'
and a.d_type = 'IN'
and a.s_type = substr('OI',0,2)
and a.g_flag = 'N'
and a.startdate <= trunc(sysdate)
and nvl(a.enddate, trunc(sysdate)) >= trunc(sysdate)
order by a.p_code
数据样本
p_master
c_code p_code
AA Test01
AA Test02
AA Test03
c_proj
c_code p_code proj startdate enddate
AA Test99 clound 01/10/2016 31/10/2016
AA Test99 clound 01/09/2016 30/09/2016
AA Test99 clound 01/08/2016 31/08/2016
我目前的结果:
c_code p_code
AA Test01
AA Test02
AA Test03
AA Test99
AA Test99
AA Test99
目标结果:
c_code p_code proj
AA Test01 null
AA Test02 null
AA Test03 null
AA Test99 clound
【问题讨论】:
-
您似乎缺少
c_inv数据
标签: sql oracle join duplicates left-join