[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Oralce query question

Posted on 2011-02-19
2
Medium Priority
?
336 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 1800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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