hi,
I have three tables named WEB, WEB_H, WEB_S. Fields in WEB are id and some other. Fields in WEB_H are id, h_id and some other. Fields in WEB_S are id, s_id and some other. In the three tables, id represent a same entity. WEB table is base table. For an id in WEB table, the matched datas may or may not be present in both, table WEB_S and WEB_H. But it is sure that atleast either of the two tables web_s or web_h has matched datas for id of WEB. What I tried to do is,
For id 14695521 from WEB, I get the data from WEB_H using left outer join and got the result as
14695521 23857780
14695521 23857781
For the same id from WEB, I get the data from WEB_S using left outer join and got the result as
14695521 38562531
14695521 38562532
14695521 38562533
I want to simply combine the result as shown below
(Manually typed)
14695521 23857780 38562531
14695521 23857781 38562532
14695521 (null) 38562533
I tried the below two queries:
1. select distinct * from
(
select
c.id,c.h_id,d.s _id from
(select distinct * from
(select
a.id id, b.h_id h_id
from
web a left join web_h b on a.id=b.id
where a.id='14695521' )) c left join web_s d on c.id=d.id
)
2. select distinct c.id, c.h_id, d.s_id from
(
select distinct a.id id, b.h_id h_id from
web a,
web_h b
where aid=b.id(+)
and a.id='14695521'
) c, web_s d
where c.id= d.id(+)
But both the queries return the result as below
14695521 23857781 38562531
14695521 23857781 38562532
14695521 23857780 38562532
14695521 23857781 38562533
14695521 23857780 38562531
14695521 23857780 38562533
Please help me to get the result as I mentioned earlier.
I have three tables named WEB, WEB_H, WEB_S. Fields in WEB are id and some other. Fields in WEB_H are id, h_id and some other. Fields in WEB_S are id, s_id and some other. In the three tables, id represent a same entity. WEB table is base table. For an id in WEB table, the matched datas may or may not be present in both, table WEB_S and WEB_H. But it is sure that atleast either of the two tables web_s or web_h has matched datas for id of WEB. What I tried to do is,
For id 14695521 from WEB, I get the data from WEB_H using left outer join and got the result as
14695521 23857780
14695521 23857781
For the same id from WEB, I get the data from WEB_S using left outer join and got the result as
14695521 38562531
14695521 38562532
14695521 38562533
I want to simply combine the result as shown below
(Manually typed)
14695521 23857780 38562531
14695521 23857781 38562532
14695521 (null) 38562533
I tried the below two queries:
1. select distinct * from
(
select
c.id,c.h_id,d.s _id from
(select distinct * from
(select
a.id id, b.h_id h_id
from
web a left join web_h b on a.id=b.id
where a.id='14695521' )) c left join web_s d on c.id=d.id
)
2. select distinct c.id, c.h_id, d.s_id from
(
select distinct a.id id, b.h_id h_id from
web a,
web_h b
where aid=b.id(+)
and a.id='14695521'
) c, web_s d
where c.id= d.id(+)
But both the queries return the result as below
14695521 23857781 38562531
14695521 23857781 38562532
14695521 23857780 38562532
14695521 23857781 38562533
14695521 23857780 38562531
14695521 23857780 38562533
Please help me to get the result as I mentioned earlier.
Comment