Solved

Oralce query question

Posted on 2011-02-19
2
327 Views
Last Modified: 2012-05-11
I have these sub-queries in Oracle (11g):

(select ID, F1 FROM ..) p
(select ID, F2 FROM ..) q
(select ID, F3 FROM ..) r
(select ID, F4 FROM ..) s

From which I need the O/P like:
ID   F1    F2   F3   F4
-----------------------
1    6      17     null null
2    null   3       8    null
3    null  4        7    2
4    3     6       11   23
5    8     null     null 22

ID is unique in the O/P.The above comes from these input values:
p:
Id  F1
-------
1   6
4   3
5   8

q:
Id  F2
-------
1  17
2  3
3  4
4  6

r:
Id  F3
-------
2   8
3   7
4   11

s:
Id  F4
-------
3   2
4   23
5  22
0
Comment
Question by:toooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 450 total points
ID: 34935081
Why could you not use the select from the other question?

Just use a simple union:
SELECT ID, MIN(F1) AS F1, MIN(F2) AS F2, MIN(F3) AS F3
FROM
(
select id,f1, null f2, null f3, null f4 from p
union all
select id,null, f2, null f3, null f4 from q
union all
select id,null, null f2, f3, null f4 from r
union all
select id, null, null f2, null f3, f4 from s
)
GROUP BY ID
order by id
/
0
 

Author Comment

by:toooki
ID: 34935200
It worked perfectly. Thank you. I changed the line
MIN(F1) AS F1, MIN(F2) AS F2, MIN(F3) AS F3
changed from MIN to MAX.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to recover a database from a user managed backup

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question