How to show a row has been "removed" from a table

We maintain rows in a table with a version number which will determine the current set of accounts for a version. I need to be able to show the changes between the versions - when a row was ADDED, REMOVED or there was NO CHANGE. I can work out ADDED and NO_CHANGE without any problem, but I'm not sure how I can determine that a row has been REMOVED when it no longer exists in the next version.
I have provided an example piece of SQL below:
with w_acct1 as
(select 'A1' acct, 0 vers from dual
union all
select 'A2' acct, 0 vers from dual
union all
select 'A3' acct, 0 vers from dual
union all
select 'A1' acct, 1 vers from dual
union all
select 'A2' acct, 1 vers from dual
union all
select 'A1' acct, 2 vers from dual
union all
select 'A4' acct, 2 vers from dual)
select a.*,
       nvl(lead(acct) over (partition by acct order by vers desc),'NULL') ld,
       case when lead(acct) over (partition by acct order by vers desc) is null then
           when lead(acct) over (partition by acct order by vers desc) = acct then
           end add_remove
from w_acct1 a
order by vers,acctWhich gives me the following result:
A1     0     NULL     NEW
A2     0     NULL     NEW
A3     0     NULL     NEW
A1     1     A1     NO_CHANGE
A2     1     A2     NO_CHANGE
A1     2     A1     NO_CHANGE
A4     2     NULL     NEW
The result I want is:
A1     0     NULL     NEW
A2     0     NULL     NEW
A3     0     NULL     NEW
A1     1     A1     NO_CHANGE
A2     1     A2     NO_CHANGE
A3     1     NULL     REMOVED
A1     2     A1     NO_CHANGE
A2     2     NULL     REMOVED
A4     2     NULL     NEW
Note the REMOVED rows associated with the version even though they don't exist in the dataset for that version number.
Can this be done with analytic functions or some other cool Oracle feature I'm missing?

You can't know about a row being removed unless you have a record of that row somewhere, either as a copy of your old data (see example below) or you've recorded the information using delete triggers etc.
SQL> ed
Wrote file afiedt.buf
  1  with old_data as (select 1 as id, 'A' as dta from dual union all
  2                     select 2, 'B' from dual union all
  3                     select 3, 'C' from dual)
  4      ,new_data as (select 1 as id, 'A' as dta from dual union all
  5                    select 3, 'X' from dual union all
  6                    select 4, 'Y' from dual)
  7  --
  8      ,ins_upd as (select * from new_data minus select * from old_data)
  9      ,del_upd as (select * from old_data minus select * from new_data)
10      ,upd as (select id from ins_upd intersect select id from del_upd)
11      ,ins as (select id from ins_upd minus select id from upd)
12      ,del as (select id from del_upd minus select id from upd)
13  --
14  select 'Inserted' as action, null as old_id, null as old_dta, as new_id, new_data.dta as new_dta
15  from new_data join ins on ( =
16  union all
17  select 'Updated',, old_data.dta,, new_data.dta
18  from old_data join new_data on ( =
19                join upd on ( =
20  union all
21  select 'Deleted', as old_id, old_data.dta as old_dta, null as new_id, null as new_dta
22  from old_data join del on ( =
23  union all
24  select 'No Change' as action, as old_id, new_data.dta as old_dta, as new_id, new_data.dta as new_dta
25  from new_data where id not in (select id from ins_upd union all
26*                                select id from del_upd)
SQL> /
Inserted                        4 Y
Updated            3 C          3 X
Deleted            2 B
No Change          1 A          1 A

Similar Messages

  • Hi. the email application has been removed from my ipad. I don't have back up so how can I get it back?

    Hi. the email application has been removed from my ipad. I don't have back up so how can I get it back?

    It is not possible to remove the Mail app (or any other of the bundled apps) from the iPad. It's probably been moved to another Home screen or inadvertently placed in a folder. If you can't find it, you can reset the Home screens in the General -> Reset preferences.

  • HT201210 Hi, the App Store icon has been removed from my iPad even after synching and updating. Any suggestions on how to get it back to be able to update / purchase apps?

    Hi, the App Store icon has been removed from my iPad even after synching and updating. Any suggestions on how to get it back to be able to update / purchase apps?

    If you do not have, or remember, the passcode for Restrictions, the only option available to you is to reset the device to factory settings via itunes.

  • Can I see how long the longest entry has been in the sticky table ?

    I have a customer who has a possible issue with the sticky inactivity timeout on the CSS. At the moment we are using no timeout, just relying on the CSS to purge the entries.
    However, is it possible to see how long the longest entry has been in the sticky table. I can see the 'elapsed time' with the 'show sticky' command but this only shows 100 entries per time and not in time order ?
    Thanks in advance for any help

    You can use the command "show sticky-table" with L3 or L4 options, depending on what you have configured, then add ip addressing to the command, to focus down to where the oldest sticky entries are likely to be, but theres no other way. If your problem is having too many entries, configure a sticky timeout, as the default of 0 will keep then forever, or until overwritten due to the table being full. If the problem is sticky entries timing out too early, you can use the timeout parameter to increase their life, but the sticky table is limited to 32k entries.

  • When I back up my  I phone 5s or my ipad2 camera roll, contacts and documents does this save in the cloud all to view even if a photo has been removed from camera roll?

    When I back up my  I phone 5s or my ipad2 camera roll, contacts and documents does this save in the cloud all to view even if a photo has been removed from camera roll?

    iCloud- Photo Stream FAQ
    iCloud- Photo Stream limits
    iCloud- How to delete photos from Photo Stream
    iCloud- Photo Stream troubleshooting
    iCloud- Using and troubleshooting Shared Photo Streams
    iPhoto '11- Add, remove, and edit photos in a shared photo stream
    iPhoto '11- Create a shared photo stream
    There are obviously limits to what can be stored in Photo Stream and for how long.
    If she wants backups then she will need something like this: Seagate Wireless Plus.

  • SL500, Product recovery function has been removed from this sytem

    I upgraded my SL500 from Vista to windows 7 OS several years ago and lately the OS has been acting weird (freezing, very slow at times) so I am thinking something is corrupted somewhere and want to restore it back to the manufacturers state.  However, when I try to do this through rescue and recovery, it tells me that the recovery function has been removed from the system.  I'm assuming that when I upgraded from Vista that R&R was no longer compatible so I installed version 4.5.  My laptop did not come with backup OS disks and was told that this was the way to restore the system back to the factory state.  How do I do this if I'm getting this message?
    try this. If this don't work then you would to reinstall the OS using the T43 recovery media disk set. 
    Jin Li
    May this year, be the year of 'DO'!
    I am a volunteer, and not a paid staff of Lenovo or Microsoft

  • Goods receipt when PO creator has been removed from org structure ?

    Hello in my organisational structure PPOMA_BBP, i have 2 users, X and Y.
    X has created a PO in the SRM portal.However , X has been removed from the org. structure.
    Is it possible for Y to make the goods recept( that is , Y logs in the portal and makes the goods receipt) ?

    Did you try to delete the user ? Did you get any error message?
    Note 1148837 - SRM user cannot be deleted
    When trying to delete an SRM user the system will check if there are still
    related SRM documents in the system. If there are active documents in the
    system the deletion is not possible. This is the correct system behaviour.
    But even if all related SRM documents are archived the deletion is
    sometimes not possible, because there are residual entries in table
    CRMD_PARTNER linked to this user.
    More Terms
    User crmd_partner residual entries deletion active document
    Cause and Prerequisites
    The attached report PARTNER_SET_DELETE will display in simulation mode all
    residual entries in table crmd_partner with invalid item or header links
    and in non simulation mode it will delete the corresponding crmd_partner
    Header Data
    Release Status: Released for Customer
    Released on: 10.03.2008 11:54:37
    Priority: Correction with low priority
    Category: Help for error analysis
    Main Component SRM-EBP-PD Procurement Document Methods
    Additional Components:
    SRM-EBP-ADM-USR SRM User Administration
    Valid Releases
    Software Component Release From
    To Release and Following
    SRM_SERVER 500 500 500
    SRM_SERVER 550 550 550
    Support Packages
    Support Packages Release Package Name
    Correction Instructions
    Ref note 550071 too..

  • HT203254 Why Mac Book Pro 17 Inch has been removed from the Apple Stores?

    while surfing the Apple web site, I found that Mac Book Pro 17 Inches has been removed from all the there any fault or some thing wrong has been detected in it?

    I heard a rumor that the 17" machines are all wearing cement shoes and at the bottom of the East River. Some guy named Soprano tipped me off.
    We aren't supposed to talk about it.

  • HT2905 The duplicate option has been removed from the latest version of Itunes. I have over 1000 duplicates and need to have a multiple duplicate removal option. How do i do that?

    I have over 1000 duplicates in both my files and in the Itunes library. The duplicate function appears to have been removed from teh latest version of Itunes. How do I identify and remove multiple duplicates from my library and my music file

    The show duplicates/show exact duplicates features have been left out of iTunes 11.0. Rumor suggests they will be restored in the next build. In the meantime I have written two Windows scripts to make playlists of Duplicates and Exact Duplicates, either from a selection of tracks or the entire library. Note that, as with the iTunes feature, this list makes no distinction between "originals" and "dupes", you have to decide which is which.
    There is also my DeDuper script for automatically removing duplicate copies but keeping one remaining copy of each set. This can preserve ratings, play counts, playlist membership, etc. which are lost in a manual clean up. Please take note of the warning to backup your library before deduping. See this thread for background on deduping and the script.
    If you want to manually remove duplicate tracks use shift-delete to remove selected tracks from the library as well as the playlist. Keep one of each repeated group of files and don't send the others to the recycle bin unless you are sure that there are multiple files on the disc as opposed to multiple entries to the same file. Same advice to backup applies.

  • How do I remove a song from my ipod that has been removed from itunes but still appears on my ipod

    I have an ipod touch and my problem is how to remove songs from it when they have been removed from itunes. After synching the songs still appear on the ipod. How can I fix this?

    Hi empty,
    Have you deleted the song from the iPod itself? Go to the songs list and swipe left on the song title. A "Delete" option should come up allowing you to directly delete the item from your iPod....

  • The Product Recovery function has been removed from this system

    I get the following error when I try full system restore - "The Product Recovery function has been reomed from this system"?
    How can I fix this?

    welcome to the forum:
    Have you made a recovery media before this problem occured??? if you haven't you may need to call Lenovo and ask for a set of recovery disks, or just use your own XP/Vista OS you got from somewhere, and load it on your machine then enter you own serial number that come with your machine.
    Then proceed to download the various softwares and drivers applicable to your machine, the most important that you won't have is the predesktop area, if you think this is unacceptable then call Lenovo and obtain recovery media from them (a nominal handling and service charge of around 50 USD will be charged).
    fill in the detail and download away.

  • Photoshop CC 2014 downloads when programme has been removed from computer.

    I had downloaded the Photoshop CC2014, Lightroom 5 and Bridge on trials but owing to a computer malfunction had to remove them.
    I wish to again download the trials but when the CC Installer has been run it tells me that Photoshop CC2014 is "up to date" yet it is no longer on the computer. Lightroom and Bridge would be able to be installed.
    Any suggestions as to how I can overcome this Photoshop problem would be appreciated

    I would like to thank those who helped with this problem.
    I have resolved the various issues. .I am using Windows 8.1 and tried various "Restore" points which helped but did not cure the problem. I downloaded and used the Adobe Creative Cloud clean-up tool which certainly helped. I then used an older version (todays version just would not run) of the Creative Cloud installer in the end and I was then able to download and install Photoshop. For some reason Lightroom 5 did not work properly but as this was listed in "Programs and Features" I was able to uninstall it; the Creative Cloud installer then enabled me to download that programme properly. 

  • Mp_statusreceiver directory over 50GB - MP has been removed from this server, but not completely?

    I had a server run out of disk space today.  Digging in, the ccm mp_statusreceiver directory had 650,000 files in it, over 50GB in size.  From what I understand, I think that folder is queuing up messages to go from a management point to the primary
    server, but the server in question had it's management point removed a couple of weeks ago.  It seems like it's still gathering data to send, but not sending it to the primary server, and filling up the drive.
    If that's the case, then it seems the management point didn't actually get removed from the server, even though it's no longer listed in the config manager console as a management point.  (The server still has a DP on it.)
    How can I clean up whatever remnants of the MP are installed on this server?

    Yes, you need a path for mp.msi. I saw that is located at C:\Program Files\Microsoft Configuration Manager\bin\X64.
    Best Regards,
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • How to identify which data has been inserted  to the table in specific date

    i created one table without data column.. i am inserting data in that table.
    i want which data has been inserted today..
    Please help.

    If you are in Oracle 10g you can use ORA_ROWSCN.Note that unless the table was created with ROWDEPENDENCIES enabled, though, ORA_ROWSCN is tracked at the block level rather than the row level. So a block with one new row and many old rows could appear as having all been entered today.

  • How to unlock ipod that has been disabled from to many password attempts

    How to unlock I pod when it has been disabled due t, to many pass word tries.

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen        
    If recovery mode does not work try DFU mode.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings

Maybe you are looking for

  • Flash content in a PDF question

    Hi, I have embeded a SWF into a PDF using InDesign CS3 and Acrobat Pro 8.1.7. The SWF displays and plays fine, I was able to set the psoter image in Acrobat and I set the border opion to no border. The only problem is that when a user clicks on the s

  • ABAP Certification & Materials

    Hi, Does anybody have ABAP certification links and materials. Please send them to [email protected] Thanks, Ramana

  • Can't sync edited pictures to iPhone.

    I can't sync pictures from iPhoto that have been edited w/ iPhone 3G. Anyone else have this problem? They won't sync to my iPod Nano 2G either.

  • Cisco Clean Access Server eth0 port inactive on install

    I am trying to learn how the Cisco NAC appliances work. I have created a small self-contained test network with a Server 2003 domain controller, a fake domain setup and some workstations joined to the domain. I have two NAC appliances, one is the Ser

  • Problems with sidecar

    i'm having problems uploading a 'sidecar.xml' with a recent folio. The folio folder is organised into article sub-folders and I have tried two options for uploading the sidecar.xml file The first was with the sidecar.xml file loose in the folio folde