select * from hc0mstr a inner join (select distinct(rl0to#),rl0fr#
from rl0reln where rl0rltyp in('BILLNG','SERVCE'')
and rl0totyp in('PHY','MBX')) as b on a.hc0hc#=b.rl0fr# left outer join lc0mstr c on
c.lc0lc#=b.rl0to#
it's my mistake I haven't checked the query. I was thinking of the joins. distinct to a specific coluln doesn't have any meaning.
if the query is like this
select * from hc0mstr a inner join (select rl0to#,rl0fr#
from rl0reln where rl0rltyp in('BILLNG','SERVCE',)
and rl0totyp in('PHY','MBX')) as b on a.hc0hc#=b.rl0fr# left outer join lc0mstr c on c.lc0lc#=b.rl0to#
Okay, the literal translation of the query would be:
SELECT
---*
FROM
---HC0MSTR---A,
---(
---SELECT
------RL0TO#,
------RL0FR#
---FROM
------RL0RELN
---WHERE
------RL0RLTYP IN---('BILLNG','SERVCE')---AND
------RL0TOTYP IN---('PHY','MBX')
---) ---------B,
---LC0MSTR---C
WHERE
---B.RL0FR#------=---A.HC0HC#---AND
---C.LC0LC#---(+)=---B.RL0TO#
However, I don't see the resoning behind making the query on B a sub-query. Therefore, the following query would be cleaner and give you the same result:
SELECT
---*
FROM
---HC0MSTR---A,
---RL0RELN---B,
---LC0MSTR---C
WHERE
---B.RL0RLTYP---IN---('BILLNG','SERVCE')---AND
---B.RL0TOTYP---IN---('PHY','MBX')---------AND
---A.HC0HC#------=---B.RL0FR#---------------AND
---C.LC0LC#---(+)=---B.RL0TO#
Of course, I'm assuming that you would replace the * with an actual list of columns, because the two statements *do* return different columns.
Bookmarks