Select the latest information

Oracle 10g

I have major paintings and Archives of the tables (the data are transferred from hand to check after some time).
I have therefore three cases here

1. the data will be present in the main tables until it is proposed to check in.
2. the data will be presented in the tables of archive if no data is found in the tables of archive
3. the data will be present in the main tables and tables of archive (IE once the data for archiving of the record movement may have received some updtaes
in this case archive aura of the old data and main table will have new data. )

so, a specific key, I have to select only the most up-to-date information. Please help me.
with emp as(select 100 emp_no, 10 dept_no from dual Union all
select 300 emp_no, 10 dept_no from dual
 )
,emp_details as (select 100 emp_no , 'Matt Wenzel' emp_name, '00000' ssn from dual Union all 
select 300 emp_no , 'Greg' emp_name, '1111' ssn from dual
),
emp_arc as 
(select 100 emp_no, 10 dept_no from dual Union all
select 200 emp_no,  10 dept_no from dual
)
,emp_details_arc as (select 100 emp_no , 'Matt' emp_name, '00000' ssn from dual Union all 
select 200 emp_no , 'David' emp_name, '2222' ssn from dual 
)
select * from emp a, emp_details b,
emp_arc c, emp_details_arc d
where a.emp_no = b.emp_no
and c.emp_no = d.emp_no;

o/p required 
---------------------
select 100 emp_no , 'Matt Wenzel' emp_name, '00000' ssn from dual union all 
select 300 emp_no , 'Greg' emp_name, '1111' ssn from dual union all 
select 200 emp_no , 'David' emp_name, '2222' ssn from dual 

Hello

Thank you for providing the sample data in a useful form. It is very useful.

new learner wrote:
o/p required
---------------------

select 100 emp_no , 'Matt Wenzel' emp_name, '00000' ssn from dual union all
select 300 emp_no , 'Greg' emp_name, '1111' ssn from dual union all
select 200 emp_no , 'David' emp_name, '2222' ssn from dual 

Is this really the output you want, or do you want the output below?
If you want that the output below, why not display the output below?

    EMP_NO EMP_NAME    SSN
---------- ----------- -----
       100 Matt Wenzel 00000
       200 David       2222
       300 Greg        1111

Here's a way to get the result of the latter:

WITH  unified_data     AS
(
     SELECT     emp_no, emp_name, ssn
     ,     1     AS source_table
     FROM     emp_details
--     JOIN     emp ...          -- if needed
          --
    UNION ALL
          --
     SELECT     emp_no, emp_name, ssn
     ,     2     AS source_table
     FROM     emp_details_arc
--     JOIN     emp_arc     ...     -- if needed
)
,     got_r_num     AS
(
     SELECT  emp_no, emp_name, ssn
     ,     ROW_NUMBER () OVER ( PARTITION BY  emp_no
                         ORDER BY      source_table
                       )     AS r_num
     FROM     unified_data
)
SELECT     emp_no, emp_name, ssn
FROM     got_r_num
WHERE     r_num     = 1
;

Essentially, it is a Request Top - N , where you want to take the lines N (N = 1 in this case) from the top of an ordered list. The tricky part here receives the data from two tables combined as if they were one. (I say two tables, not four, because emp and emp_arc are not needed for the output you posted. If they were needed, then you may reach them at emp_details and emp_details_arc inside the sub-0query, called unified_data, as indicated by the comments.)

Tags: Database

Similar Questions

  • The latest information on the blue screen error 0x0000c1f5?

    I've found so far no 'Good' news about this error. Someone knows a way to fix or start in safe mode?

    Thank you!

    CCRRICH

    You don't say what you were doing or how it occurred.

    Read on... http://support.Microsoft.com/default.aspx/KB/946084

    "Stop error message when you start a Windows Vista-based computer:"0x0000C1F5"

    See you soon. Mick Murphy - Microsoft partner

  • In SharePoint 2010 - is there a method of verification and registration the users accessed to the latest version of a document.

    My industrial group is highly regulated by the Govt. We must prove that a 'intangible' has the latest information. We produce paper distribution of textbooks and also accommodate electronic download. When new versions of the document are available, we must inform the censitaires, the distribution effect and monitor the incorporeal receipt verification.

    Hello

    Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT audience Pro on MSDN. Please post your question in the MSDN Forum. You can follow the link to your question:

    http://social.msdn.Microsoft.com/forums/en-us/category/SharePoint/

    Hope the above information is helpful.

  • Select the last 50 closed records

    The research of a statement select simple sql which selects the latest 50 records closed in the database.

    I found some help out there who have an example like:

    SELECT RecordID, closed_date
    (SELECT RecordID, closed_date, RANK() over (ORDER BY closed_Date DESC) date_rank
    FROM table1)
    WHERE the date_rank < = 50;

    Only problem is, this is to select something like 4000 recordings, and many of them are not yet closed.

    I think that you need to retrieve the records that are only closed in the first place.

    Try this,

    SELECT RecordID, closed_date
      FROM (SELECT RecordID,
                   closed_date,
                   ROW_NUMBER () OVER (ORDER BY closed_Date DESC) rn
              FROM table1
             WHERE closed_date < SYSDATE)  --Notice this.
     WHERE rn <= 50;
    

    G.

  • How to get the latest fix for CPU

    Hi gurus,

    Hello.


    How to get the latest information from CPU fix for our system EBS 11i, how to get alerts whenever they have released patches of CPU.

    Hi DBA.

    Please check this, hope this helps.

    See the metaink notes:

    Releases of Oracle E-Business Suite 11i and 12 Critical Patch Update knowledge Document (October 2010) [ID 987438.1]

    Information OCT - 2010 CPU patches:

    http://www.Oracle.com/technetwork/topics/security/cpuoct2010-175626.html

    on the paths of the CPU:

    http://www.Oracle.com/technetwork/topics/security/alerts-086861.html

    For the email subscription:

    http://www.Oracle.com/technetwork/topics/security/securityemail-090378.html

    Published by: Amigo on December 22, 2010 07:26

    Published by: Amigo on December 22, 2010 07:29

  • I have a Mac Book Air of 2015 running El Captain I see the airplay icon in my menu bar and I've upgraded to the latest version of the software on my AppleTV 2 but I can not Airpay icon on the menu bar of my mac to turn blue when I select the apple TV conn

    I have a Mac Book Air of 2015 running El Captain I see the airplay icon in my menu bar and I've upgraded to the latest version of the software on my AppleTV 2, but I can't get the Airpay icon on the menu bar of my mac to turn blue when I select the apple TV connected to a HD from LG smart TV. Help!

    Hi, Arghbee1.

    Please visit Apple support communities.

    I understand that you are unable to AirPlay from your Mac to your Apple TV.  Here are some troubleshooting steps that I recommend to go through this problem.

    Get help

    If you do not see the AirPlay icon , make sure that your Apple TV is awake and that it meets the system requirements.

    If you do not see your Apple TV in the AirPlay menu, make sure that your Mac and Apple TV comply with the system requirementsand your software from the Apple TV is updated. Also check your firewall settings:

    1. Choose the Apple menu > System Preferences, click Security & Privacy, and then click the Firewall tab.
    2. Click the lock icon and enter an administrator name and password.
    3. Click Firewall Options.
    4. Deselect the option "block all incoming connections".
    5. Select the option "automatically allow signed software to receive incoming connections.

    If your office does not look great on your HDTV, high-definition TV could apply image quality improvements that are not the best for the computer images. Check the manual of your HDTV for more information on how to adjust your HDTV settings for use with a computer. Your HD TV could offer a more appropriate display mode, such as the computer or game mode mode. Also try adjusting the HDTV settings like sharpness, retail building and noise reduction.

    If you mirror your screen and the image correspond to your HDTV screen, you can adjust the size of the Office for the best image. Click the AirPlay icon, and then select an option under "game size desk to." If you fit to desktop size to your Apple TV, the image fills the screen HDTV but will not look as good on your Mac screen. Learn more about overscan and underscan and what you can do about it.

    If AirPlay disconnects itself, your wireless network can be too busy or have too many wireless interference to maintain the connection of the antenna. Learn how to solve the problems of Wi-Fi connectivity. The manual of your router network may have additional suggestions for maintaining a strong and fast connection with your devices.

    Use AirPlay to view a video of your Mac on a HDTV

    See you soon

  • Play 'For You' selections is sending me to 'Browse' in the latest version of iTunes

    Anyone having problems with the latest version of iTunes (12.5.1.21) when trying to play selections of "For You" and sent to "Browse"?

    And then nothing. Same problem here. I just can't get anything to play on 12.5.1.

  • I was prompted to download the latest version of firefox and I selected restart later... I don't want to download this version... you can cancel it for me?

    The last time that I downloaded the latest version of firefox that all my favorites have been removed. I don't want to download the latest version - please help

    No, you protect your personal data when you update Firefox.

    Firefox stored the personal data in the profile folder.

    If you are concerned then make sure to back up your data regularly.

  • Until the latest update when the AutoComplete bar has been selected, he "went" no other by clicking. I must now click the refresh arrow. It won't work even with the return. How can I operate the old way easier?

    Until the latest update when the url I wanted in the address bar of AutoComplete has been selected, it "accompanies" no more further by clicking on. I must now click the refresh arrow. It won't work even with the return. How can I operate the old way easier?

    You can disable this extension in tools > Modules > Extensions and close and restart Firefox normally.

  • Information about the latest drivers for Qosmio E10 / F10 / G10

    Hey all, I don't know if a used Toshiba computer support on the European site of bed this thread, but I hope of course.

    Well it turns out that a little Japanese knowledge so I decided to go to the Toshiba Japan website, in the download section of pilot, and I was a bit shocked ^_^

    For my Qosmio E10, I realized that most of the downloads from the European websites of Toshiba are outdated.

    -There is a new version of the bios 1.70 (which improves stability with Intel chipset AFAIK) instead of on the site of the Euro 1.60. [I didn't try it because my machine is a French]

    -New Nvidia video drivers! 57,82 versus 57,79 on the site of the Euro. [I tried and there are new presets for PC games]

    -New driver tuner TV 1.0.2.6 versus 1.0.2.0 on the site of the Euro.
    [I tried and what a TOTALLY SOLVED MY TV PROBLEMS CHECK, I can finally save all: PAL, SECAM & NTSC without huge flicker that plagued the 1.0.2.0 version]

    -Toshiba offers 'Toshiba Virtual Sound' for owners of the E10 to the Japan. (in Europe, we still have the "Windows Media player SRS WOW" plugin) [I tried and it is a fantastic software, improvement of the sound is great with great presets, you won't believe what you get for your Harman/Kardon after installation of this!]
    It has the great advantage of working for all the Windows programs, not only in WMP as the fact the plugin 'SRS WOW' we have in Europe.

    As you can see there are a lot of new drivers that we, owners of European Qosmio, would really benefit.

    But there's something interesting that you should know about:
    Drivers Toshiba E10 euro site are also outdate compared to other Qosmio models pilots from the Euro site!
    For example:
    -The pilot of his "Soundmax", is a version of 3890 in section E10 and 5160 in the section of the G20!
    It's exactly the same chipset, so it is of course compatible and should also be in the section of the E10.

    -L'Intel LAN driver "INtel PRO 100 VE" is version 7.1 in the section of the E10 and 8.0 in the section of the G20.

    -L' utility development of photo is the version 2.4.0.0 for E10 and 2.7.0.2 for the G20.
    P.E.U. is a key point for Qosmio because he is directly responsible for the quality of image engine Qosmio!)

    I think it's a hassle to go to the other models Qosmio download section to find the latest drivers for our machines.
    Qosmio E10 is a year old and is a fantastic (and expensive ^^) piece of hardware, Toshiba please, update the drivers at the latest as soon as you can.

    It's about the E10, but if you have a F10, G10, I'm sure you can do the same thing as me and go see the download section of the F20, G20, etc... and you will find the latest drivers and downloads for your machine!

    As for now, I really hope that Toshiba would be the BIOS for EURO Qosmio E10 1.70. (For Japanese E10, it is located here: http://dynabook.com/assistpc/download/modify/bsqse102/index_j.htm?qry=.%2F%3Ffunc%3Dpi%26category%3D1310 20% 26keyword % 3Dqosmio % 26cpg %3 D 50% 26session %3 D 027063644820 20051)

    If a moderator of this forum is able to convey this message to the person concerned to Toshiba, it would be extremely useful too ^^

    Thanks for reading.
    Next time!

    Alcahest

    Hello.

    Thanks for this information. It seems that you are passionate about Qosmio :)
    Well, I think that the Japanese unit models differ a bit like a European models also the utilities and drivers. It of strange that the other drivers work correctly but
    I'm sure that if the new driver, tools and utilities are available for European units you will find this on the site of Toshiba Europe.

    Good bye

  • I used numbers for a long time, but only make spreadsheets base.  With the latest updates, I couldn't change my information.  What Miss me?

    I used numbers for a long time, but only make spreadsheets base.  For about a year and with the latest updates, I couldn't change my information.  What Miss me?

    Hi Deb,

    There not really enough information in your message to help you. How things don't work, exactly? Is there any alerts or messages?

    Quinn

  • I'm not finding a choice selection of development under my Select drop-down list.  I use the latest version of Photoshop CC

    I'm looking in the wrong place for the new development tool in the latest version?  I'm looking under Select but don't see no choice.

    Thank you, Bob

    As I suspected, you run the old software.

    32 or 64-bit isn't the issue here.

    Adobe has released Photoshop CC version (2014) as a completely separate release, which installed in a completely different place that the CC Photoshop 14.x you are running.

    You must find that place and update the process that you use to start the application to launch the new version.

    -Christmas

  • To restore the backup of information to my new iPhone 7, I had to update iTunes.  I did it on my computer, but when I plug my phone into the computer, it tells me that I need the latest version of iTunes.  What should I do?

    I downloaded the latest version of iTunes to restore the backup of my new iPhone 7.  When I plug my computer into iPhone 7, I get the message that I need to update iTunes.  It is to show that I have updated the latest version, so I now do not know what to do.  Need help!

    In iTunes, go to the ' about iTunes' topic. What version do you currently use?

    What version of OS are you using on your computer?

    Your new phone should you use iTunes 12.5.1 requiring 10.9.5 OSX or higher.

  • When I try to download the latest Flash vs information in the login box has the incorrect ID. I can get on the Web site at the address (not the password... address) but the download area.

    I'm having a problem with my sign on info incorrect when I try to download the latest Flash vs It has my name my name sign - not what I use to sign in adobe. How can I fix it? The Web site he has correctly.

    Hello

    The password is displayed by your system, no Adobe and the password that you use to connect to your computer, not the Adobe ID password.  Please see what userid & password I need to install Flash Player?

    --

    Maria

  • Scrapie to screen using the latest version of firefox

    Just noticed my screen flickered when all the pages scroll.
    I tried to activate and deactivate hardware acceleration and even still images.
    IM using the latest version of firefox and this problem does not occur with Internet Explore.
    I have a problem with the flash from time to time, where the solution is simple disable or restart firefox.
    I also have the latest version of flash.

    Safe mode disables all modules and user settings. If that happens again
    with all the add-on disabled, it may be a setting under Subject: config

    Type Subject: support in the address bar and press on Enter.
    Under the main banner, press the button; Copy the text to the Clipboard..
    Then in the box to answer at the bottom of this page,
    right-click the area and select block.
    This will show us the details of your system.
    No Personal Information is collected.

Maybe you are looking for

  • Link to iTunes 1.1.1 or Older

    I have an iMac G3 with Mac OS 9 and OS X 10.0 Cheetah. I would like to get iTunes installed on Leopard, does anyone know a link for iTunes 1.1.1 or more. There is a link for iTunes 1.1 to support.apple.com/downloads/itunes. But it does not work so un

  • My t420s runs at a normal temperature?

    I just bought a used thinkpad t420s and I was wondering if it is overheating or running at the right temperature. The CPU is idling in the middle to low 50 (degrees Celsius) and will reach 95 degrees Celsius 95 premium running. When running a virus s

  • How I have "chosen" a device in XP?

    How I have "chosen" a device in XP?   I hit mistakenly ignore this device when I plugged in my iPhone and now my computer does not recognize my iPhone.

  • Accoud messed up user

    On my home computer (which runs on windows xp) my user account is empty. My files are their but my user account from desktop PC and everything is similar to how it was when I got it. My shortcuts and everythings are missing from my desk, wallpaper is

  • Windows 7 is enabled is no longer

    I have upgraded to windows 10 a few weeks ago and don't like it so I went back to windows 7, but, since he says that my copy of windows 7 was not authentic. Is there a way I can make real new without having to buy a new OS?