Solved

Oralce query question

Posted on 2011-02-19
2
315 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
2 Comments
 
LVL 76

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now