How do I return the results of two SELECT statements in to one result?

I want to do this without using UNION.
Here's an example of what I'm trying to do:
I have a table called COUNTRY with the following columns:
COUNTRY
COUNTRY_CODE
DATE_VISITED_LAST
POPULATIONI have another table called STATE_COUNTY with the following columns:
STATE_COUNTY
COUNTRY_CODE
STATE_COUNTY_CODE
DATE_LAST_VISITED
POPULATIONI have a third table called TOWN with the following columns:
TOWN
COUNTRY_CODE
STATE_COUNTY_CODE
TOWN_CODE
DATE_LAST_VISITED
POPULATIONNow through the interface I have, a user will supply a country code. I need a SELECT statement that will return a table with the following result set:
The COUNTRY_CODE entered including the DATE_LAST_VISITED and POPULATION for this country
------> All the associated STATE_COUNTY's belonging to this country along with the DATE_LAST_VISITED and POPULATION for each STATE_COUNTY_CODE.
-------------> All the associated TOWN_CODE's belonging to this state_county and country along with the DATE_LAST_VISITED and population for each TOWN.
So the table will have 9 columns:
COUNTRY
DATE_LAST_VISITED_COUNTRY
POPULATION_COUNTRY
STATE_COUNTY
DATE_LAST_VISITED_STATE_COUNTY
POPULATION_COUNTY
TOWN
DATE_LAST_VISITED_TOWN
POPULATION_TOWNAny ideas how this can be done?
Thanks.

Hi guys,
Would it be ok to do it like this (with a join):
SELECT      
     c.country_code,
     c.date_last_visited AS DATE_LAST_VISITED_COUNTRY,
     c.population AS POPULATION_COUNTRY,
     s.state_county_code,
     s.date_last_visited AS DATE_LAST_VISITED_STATE_COUNTY,
     s.population AS POPULATION_COUNTY,
     t.town_code,
     t.date_last_visited AS DATE_LAST_VISITED_TOWN,
     t.population POPULATION_TOWN,
FROM
     country c
     LEFT OUTER JOIN state_county s ON s.country_code = c.country_code
     LEFT OUTER JOIN town       t ON t.country_code = s.country_code
AND                                       t.state_county_code = s.state_county_codeThe results required would be something like:
Country_Code     DATE_LAST_VISITED_COUNTRY     POPULATION_COUNTRY     STATE_COUNTY_CODE         DATE_LAST_VISITED_STATE_COUNTY         POPULATION_COUNTY     TOWN_CODE     DATE_LAST_VISITED_TOWN     POPULATION_TOWN
UK               14-JAN-09                     56,00000               London                    18-JUL-99                              23,0000               Ascot         30-JUN-89                  12,000
                                                                                                                                                             Brixton       28-JAN-92                  4,684
                                                                      Birmingham                12-SEP-09                              55,678                Solihull      12-OCT-81                  6.768 Does this make sense?
Thanks!
Edited by: Sastry on Nov 2, 2009 2:04 AM

Similar Messages

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • I just upgraded on May 11 and find I cannot open a fold for bookmarks. I research and bookmarks are my lively hood. How can I return the bookmark functionality?

    MS 7 and long time user of Firefox so this is the recent upgrade of May 11. Unlike the prior bookmark functionality, I cannot indicate I want to bookmark a link and designate a new folder for a new topic in two to three clicks. This is critical to what I do for a living. How can I return the prior format and be sure bookmarks are backed up automatically. Does going back to the older and more functional tool bar restore this? And why does clicking the bookmarks toolbar show getting started, most visited and the printer icon? Getting started takes one to a new user set of instructions. But there are no functional operations in the tool bar? I am not going to go thru a lot of commands, this should be a automatic as before.

    '' the bookmark facility is not functional in 29 ... Bookmark puts all bookmarks there into "recently bookmarked" ''
    It does not.
    It works much the same as the old system does. Or at least it should do and does do for me.
    * Carefully reads the following article so you are certain what should be happening '''[[How to use bookmarks to save and organize your favorite websites ]]'''
    # From an unbookmarked page click the bookmarks star.
    #* That results in the bookmark being added, and yes initially it is just as an unsorted bookmark. (No doubt that is where most people put most bookmarks)
    # IMPORTANT click the star a second time. (But not so rapidly it counts as a doubleclick)
    #* You now have the options you had in the old version of Firefox <br /> Create new folders <br /> Save to a recently used folder <br /> Show all bookmark folders - and expand nested folders
    If your bookmarks are not working possibly the file is corrupted in which case see
    * http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox#Damaged_Places_database
    I am hoping it is just that you are doubleclicking the star too quickly.

  • How do you merge the data of two MIDI regions?

    How do you merge the data of two MIDI regions into one MIDI region without using copy and paste functions in the piano roll editor?

    Sorry - didn't make myself clear. The glue tool would be no good here. I meant that I wanted, for example, to merge the MIDI contents of two regions that are perhaps on different tracks but play back at the same time, i.e. I want to add the 2nd region's MIDI to the 1st region's MIDI, but without having to go into the piano roll editor and cut and paste the data.

  • How do you return the number of Rows in a ResultSet??

    How do you return the number of Rows in a ResultSet? It's easy enough to do in the SQL query using COUNT(*) but surely JDBC provides a method to return the number of rows.
    The ResultSetMetaData interface provides a method for counting the number of columns but nothing for the rows.
    Thanks

    No good way before JDBC2.0. u can use JDBC2.0 CachedRowSet.size() to retrieve the number of rows got by a ResultSet.

  • How can I return the current Date in Java?

    I am new to Java, and basically I want to know how I can return the current date as a variable, so for example, I have declared the following date variable
    private java.util.Date currentDate;How can I return the current date, do I have to write a method? To be more specific, I need to write a setMethod, that simply returns the current Date in Java.
    Please point me in the right direction.
    Thanks,

    If all you want is a date for printing or displaying, the easiest way is to use Date as shown below. If you need something more complex, look at the Calendar API.
    import java.util.Date;
    class DateEx
         public static void main(String args[])
              Date now = new Date();
              System.out.println(now);          
    }

  • How can i compare the contents of two folders ?

    how can i compare the contents of two folders and find out which files are in one but not in the other?? Knowing how to do this would be the best thing ever, especially when dealing with a large number of files. Often, for instance, I'm dealing with a large number of images, processing them, and saving the retouched ones to a new folder, and need to check that they are all there. If there are say three files missing in the second folder (out of say a hundred in total) being able to automate the process of elimination would be very useful. Please help!!!
    B

    I really wish I knew the answer to this. I work between two macs, a G5 and MacBook Pro when I'm on the go. Each time I move from one to the other I have to copy all my files to the computer I'm going to work on, so I end up with the same files being duplicated. It's not a problem if it's not much data but in my case the it can be to 30GB, mostly graphics files, photoshop, motion, final cut pro, etc.
    There's has got to be a way automator can make a comparison between two folders to sort out what's changed and what's remained the same. It would be nice also if this feature could be done globally on the hard disk using spotlight's technology to stop files being duplicated in places you didn't even know about and taking up valuable disk space. I'm not sure how this could be done.
    Any bright ideas Apple?

  • TS1702 How can I return the app that I bought for my iPhone4S almost three months ago.

    How can I return the app I bought almost 3 months ago? Is this to late to return??

    Apps are not returnable. They're also very difficult to wrap.

  • How I can return the replication groups to be in the normal state again?

    Hi All,
    can anybody help me on the following issue:
    after executing "*exec dbms_repcat.suspend_master_activity(gname=>'RG_EARMS');*"
    I got the following and it rejected to resume the replication again:
    SQL>select job, what from dba_jobs where what like '%do_deferred_repcat_admin%' ;
    JOB WHAT
    31 dbms_repcat.do_deferred_repcat_admin('"RG_ELEDGER"', FALSE);
    34 dbms_repcat.do_deferred_repcat_admin('"RG_ETBR2"', FALSE);
    4 dbms_repcat.do_deferred_repcat_admin('"RG_COMMON_PROCS"', FALSE);
    55 dbms_repcat.do_deferred_repcat_admin('"RG_EFAST"', FALSE);
    7 dbms_repcat.do_deferred_repcat_admin('"RG_EFX"', FALSE);
    35 dbms_repcat.do_deferred_repcat_admin('"RG_ESTS"', FALSE);
    9 dbms_repcat.do_deferred_repcat_admin('"RG_ESCHEDULES"', FALSE);
    75 dbms_repcat.do_deferred_repcat_admin('"RG_EARMSG"', FALSE);
    32 dbms_repcat.do_deferred_repcat_admin('"RG_CSIUSER"', FALSE);
    155 dbms_repcat.do_deferred_repcat_admin('"RG_ETOOLS"', FALSE);
    10 rows selected.
    SQL>
    select gname, status from dba_repgroup;
    SQL>
    GNAME STATUS
    RG_ETBR2 NORMAL
    RG_COMMON_PROCS NORMAL
    RG_EFAST NORMAL
    RG_EARMS              QUIESCING
    RG_EFX NORMAL
    RG_ESTS NORMAL
    RG_ESCHEDULES NORMAL
    RG_EARMSG            QUIESCING
    RG_ELEDGER NORMAL
    RG_CSIUSER NORMAL
    RG_ETOOLS NORMAL
    11 rows selected.
    SQL> select id, gname, status, master, source, oname, request
    from dba_repcatlog
    order by gname, id;
    no rows selected
    the database version is 9.2.0.8.0
    the OS is SunSolaris 9
    so, how I can return the above groups to be in the normal state again?
    Thanks and Best Regards,
    Shereif
    Edited by: user642590 on Aug 6, 2009 8:13 PM

    I don't see an "dbms_repcat.do_deferred_repcat_admin('"RG_EARMS"') job.
    The RepGroup would be quiescing but not quiesced if there are active, uncomitted transactions.
    What is the error you get when you attempt to resume -- I guess that the groups are in the queiscing state ?

  • HOW DO i RETURN THE DOWNLOADED PHOTOSHOP ELEMENTS 12

    HOW DO I RETURN THE DOWNLOADED PHOTOSHOP ELEMENTS 12?

    Well, this is not the Elements forum, but…
    Unfortunately, only Adobe customer service can assist you with your issue. These are user forums; you are not addressing Adobe here.
    Click on the link below, and after that click on "Still need Help? Contact us."
    Then on the next page, click Chat
    There is also a phone option.
    http://helpx.adobe.com/contact.html?step=PHXS_downloading-installing-setting-up_licensing- activation
    © 2014 R_Kelly

  • U410 Windows 8 how do you split the screen in two?

    I have an IdeaPad U410 with Windows 8 as an Operating system. I would like to know how do you split the screen in two. Also I would like to know if I can put my screen as a touch?
    Moderator Note; subject edited for relevancy

    hi BoJ,
    Welcome to the Lenovo Forums.
    If you're referring to having an extended display , you will need to have an external monitor and enable extended mode by pressing the Winkey+P and select Extend.
    If you want to split the screen to work with 2 documents or 2 windows at a time, you can snap the windows by pressing Winkey+ Left or Right arrow - check this article in reference.
    Hope this helps
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as an "Accepted Solution"! This will help the rest of the Community with similar issues identify the verified solution and benefit from it.
    Follow @LenovoForums on Twitter!

  • Return the difference between two strings

    Is it possible to return the difference between two strings?
    For example
    String one = "We went for a walk";
    String two = "We went for a run";
    compare "two" to "one" returns "walk"
    compare "one" to "two" returns "run"I need to return the difference of two strings, one prior to editing and one after editing.
    Then I want to return any difference between the two, which will be the effect of the editing.
    Cheers Alex

    Interesting problem. Before you start writing any code, make up a whole bunch of test case pairs. Decide what the difference between the pairs is. When you start seeing patterns, analyse them. After a while you may have enough data to start writing your program. Here's one test case to get started with:"I saw the cat eat a rat"
    "My cat is hungry"

  • How do I return the VI path of a test step in LabVIEW?

    I'd like to create a VI that will return all the VI paths that are associated with the test steps in a TestStand sequence.  How do I return the VI path associated with a test step?  Below is a starting point that returns the first step in the sequence.
    Solved!
    Go to Solution.

    Thanks a lot, Allen.  Exactly what I was looking for.  Here is the code that worked:

  • How can I return the audio book which I never downloaded?

    How can I return the audio book which I never downloaded?

    All purchases are considered final whether or not you decide to download them, but you can try the 'report a problem' link to contact iTunes Support and see if they will credit or refund you : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Hi there, I have much files saved on pages ( ios ipad) , I just open it today and did not find .all the files !!!! Just 4!!! Taken in consider that I did not delete or making any wrong action. How I can return the lost files!!!! Help please

    Hi there, I have much files saved on pages ( ios ipad) , I just open it today and did not find .all the files !!!! Just 4!!! Taken in consider that I did not delete or making any wrong action. How I can return the lost files!!!! Help please
    its very important files!

    tis true
    I know, I always do that but I was in a rush to get somewhere and I was relying on my thousand dollar Mac to do some kind of recovery or something. I know Microsoft always keeps temporary files (I think Mac does too, part of me asking here in this forum was for someone to tell me where I can find those files) and when you go to open Office Works then it gives you the option of opening the last recent documents, saved or not saved.
    I usually copy paste into my emial just in case something goes wrong with the created document but I just didn't have the time to login and do all that My loss, you live and you learn, BUT still if ANYONE got any info on this, PLEASE DO CHIME IN *keeping the hope alive*

Maybe you are looking for