SQL to find highest version of multiple updated copies of rows

Hello,
I have an Archive table the stores archived versions of updated rows from the Main table. Each time a Main row is updated, a copy of it is copied to the Archive table with the next version number of a sequence.
The Archive table has three columns: Title -- MessageId -- Version.
Here is some sample data, showing three versions of messageid = 101 and two versions of messageid = 102:
Title -- MessageId -- Version
title abc -- 101 -- 1
title xyz -- 101 -- 2
title mno -- 101 -- 3
title jkl -- 102 -- 1
title opq -- 102 -- 2
My goal is to do a query that might work like this:
select title, messageid, max(version) from Archive group by title, messageid;
-- so that I get this result set:
title mno -- 101 -- 3
title opq -- 102 -- 2
Can somebody please me with the SQL to get this kind of result? Any suggestions are greatly appreciated.
Thank you,
Logan

Here are two generic ways I think will work (haven't tried 'em):
select title, messageid, version
from archive
where (messageid, version) in
  (select messageid, max(version)
   from archive
   group by messageid)
select a.title, a.messageid, a.version
from archive a,
  (select messageid, max(version) as max_version
   from archive
   group by messageid) b
where a.messageid = b.messageid
   and a.version b.max_versionThere's probably a more efficient Oracle-specific way using the anaylytic functions, but I can't think of how to do it at the moment...

Similar Messages

  • Multiple updates to same row

    Hi experts,
    I still cant figure out how oracle handles multiple updates to the same row. For instance I have 3 update statements:
    update supplier set supp_type = 'k' where supp_code = '1';
    update supplier set supp_type = 'j' where supp_code = '1';
    update supplier set supp_type = 'm' where supp_code = '1';
    I keep getting the final result to be supp_type = 'k' where it should actually be 'm', but when i execute the mapping it shows 3 update operations, which baffled me as to how oracle handles simultaneous updates to same row. I even tried disabling parallel dml on the table object, but am unsure whether this actually helps. I try putting a sorter operator and then a key lookup operator after the sorter operator in my mapping to compare the supp_code field in the sorter with the target table's supp_code field to retrieve the relevant row to update, but instead of 3 update operations, it now updates all supp_type in all my records to NULL. Can anyone explain to me how i should go about dealing with this?

    Hi experts,
    I just took a look at the code section generated for the key lookup operator named SUPPLIER_WH_SURRKEY01 and I feel something is wrong with the generated code. I have pasted the code section on the key lookup operator below.
    ORDER BY
    "SUPPLIER_CV"."RSID$" ASC ) *"SORTER" ON ( ( ( "SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = "SPIDERWEB2"."GET_EXPIRATI_0_EXPIRATI" ) ) AND ( ( "SUPPLIER_WH_SURRKEY01"."SUPPCODE" = "SORTER"."SUPP_CODE$1" ) ) )*
    WHERE
    ( ( "SUPPLIER_WH_SURRKEY01"."SUPPKEY" IS NULL ) OR ( "SUPPLIER_WH_SURRKEY01"."SUPPKEY" = "SUPPLIER_WH_SURRKEY01"."SUPPKEY" ) );
    Can anyone explain to me the codes in bold? I have no clue as to what it means? Furthermore, those bold-ed codes look similar to what I have expected to find in the where clause, except that instead of SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = "SPIDERWEB2"."GET_EXPIRATI_0_EXPIRATI", I expected to find
    SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = '31-dec-4000', because my key lookup operator checks upon a constant with the value '31-dec-4000'. And the constant name is CONSTANT itself, while my mapping's name is SPIDERWEB2(not too sure why the generated code refers to my mapping name instead of my constant)
    Edited by: user8915380 on 17-Mar-2010 00:52

  • Script to remotely find IE version across multiple PC's

    Hoping someone can help...I'm very new to Powershell and it seems very powerful, but I'm having trouble to execute commands across multiple pc's.  I can use powershell to find the IE version on my local machine, but I'd like to be able to pull from
    a TXT file (list of PC's)  the IE Version and export it to CSV format
    If anyone has any idea, I'm up for testing.
    Thank You

    Post you script and the error messages.
    ¯\_(ツ)_/¯

  • Powershell script to find Office version on multiple PC's not working- Please Help?

    Hello!
    I am about to go mad with this script. Can you help?
    I am trying to search the PC’s on my domain for what office version they are running. (I am looking for any PC’s that still have Office 2003 installed).
    Here is my script:
    foreach ($computer in (Get-Content
    PClist.txt)) {
      $version = 0
      $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
      $reg.OpenSubKey('software\Microsoft\Office').GetSubKeyNames()
    |% {
        if ($_ -match '(\d+)\.')
          if ([int]$matches[1] -gt $version)
            $version = $matches[1] 
      if ($version)
          "$computer
    : found $version" 
        else {
          "Could
    not find version for $computer" 
    It runs, but returns bad results. PC’s I know to have 2003, say they have version 13 (2007), and PC’s I know to have 2010 are showing up with version 11 (2003). Some PC’s report correctly.
    Also, some PC's from PClist.txt are not even turned on, but are returning info. Weird.
    Do you have any idea what I am doing wrong?
    ANY help would be really appreciated.
    Thanks in advance for any help you can give!

    That is easy.  YOu cannot deteermine the installed verion that way.  THe key will have keys for all versions that have ever been installed.  I f you have installed a viewer that is newer then the newest key will be there.
    Try this and ytou will see waht I mean
    Get-Content PClist.txt |
        ForEach-Object{
            $reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
            $reg.OpenSubKey('software\Microsoft\Office').GetSubKeyNames() |% {$_}
    jv

  • Where can I find earlier versions of Software update.  Have 6.03 want 6.02

    Trying to edit a project that was started in 6.02. I have 6.03 at home but need the project to stay in 6.02 because I will master it out at a location that refused to upgrade.
    I have reinstalled FCP back to 6.0 (at home). Now I am trying to find the update to get me to 6.02. IS this possible? Apple only gives me the choice of 6.04 when I search here. Any leads? is this hidden somewhere in the support world?

    I wish Apple would do that too.
    Now you can't even get 6.0.3...because 6.0.4 was released yesterday.
    What you CAN do is export your cut as an XML v4 and then import that into the machine at work. I do that all the time and it works like a charm.
    Shane

  • How to merge with multiple updates

    Hi All,
    can someone help with merge and multiple updates when matched ?
    create table foo
    id number,
    name varchar2(30),
    col1 date,
    col2 date
    create table bar
    id number,
    name varchar2(30),
    col1 date,
    col2 date
    insert into foo values ( 1, 'test1', sysdate + 30, sysdate);
    insert into foo values ( 2, 'test2', sysdate + 30, sysdate);
    insert into foo values ( 3, 'test3', sysdate + 30, sysdate);
    MERGE INTO BAR T1
    USING (SELECT id, NAME, col1, col2 FROM foo) T2
    ON (T1.id = T2.id)
    WHEN MATCHED THEN
    UPDATE SET T1.NAME=T2.NAME where T1.Name != T2.Name
    UPDATE SET T1.col1=T2.col1 where T1.col1 != T2.col1
    UPDATE SET T1.col2=T2.col2 where T1.col2 != T2.col2
    WHEN NOT MATCHED THEN
    INSERT (ID, NAME, col1, col2 ) VALUES (t2.Id, t2.NAME, t2.col1, t2.col2);
    Reason for having multiple updates to same row is i want to update the column only if name, col1, and col2 columns have changed. So, I want to first match by rows and then update the columns in bar that have changed in foo.
    Any thoughts on how I might do this in merge ?. I get the foll. error
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Thanks
    Vissu

    I think you will be better off reading this link.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9016.htm#SQLRF01606
    It will be something like this.
    MERGE INTO BAR T1
    USING (SELECT id, NAME, col1, col2 FROM foo) T2
    ON (T1.id = T2.id)
    WHEN MATCHED THEN
    UPDATE SET T1.NAME=T2.NAME ,
                          t1.col1 = t2.col2 ,
                          t1.col2 = t2.col2
    where T1.Name != T2.Name or t1.col1 != T2.col1 or t1.col2 != t2.col2
    WHEN NOT MATCHED THEN
    INSERT (ID, NAME, col1, col2 ) VALUES (t2.Id, t2.NAME, t2.col1, t2.col2);Please note this code is untested.
    Regards
    Raj

  • HT4623 I have an IPad Model MC497LL with version 4.2.1 (8C148) where do I find system updates to get this device to the highest version possible for this model?

    I have an IPad Model MC497LL with version 4.2.1 (8C148) where do I find system updates to get this device to the highest version possible for this model?

    Go back to the article you asked this question from, ignore the instructions for updating it wirelessly, scroll down, and follow those for updating it from iTunes on a computer.
    (93330)

  • In the latest version of Pages (5.0) I cannot find the refresh button to update a chart copied from Numbers (also latest version 3.0). Can anyone help?

    In the latest version of Pages (5.0) I cannot find the refresh button to update a chart copied from Numbers (also latest version 3.0). I saved my Numbers document before copying to Pages. Can anyone help?

    I think you identified my mistake. I confused tables-charts-graphs. I was wanting a "table" of cells (numbers) to be added to the Pages document. Is there no way to do that and keep the tables linked between Numbers09 and Pages09?
    An example would be a Numbers spreadsheet calculating a number (say, a product price) and that number (data) be linked to a product information text in Pages.
    I just recently saw the Merge function in Pages, but have not yet learned how that works. I don't use Pages much at all but it would come in handy for creating to information sheets about products --- with the product pricing being updated from a Numbers spreadsheet.
    If you have any hints on how that can be done or where I can find info on that I would appreciate it.
    Thanks for catching my misunderstanding.
    Bill

  • How to find firefox version without triggering an update?

    I've disabled update in every way imaginable (no lectures please) but i an update starts regardless when i go to help / about firefox. Is there any other way i can check the version without triggering an update?
    thanks.

    Hello!
    You can find the version of your Firefox (along with other troubleshooting options, if you need it later) by entering ''about:support'' in the Awesome Bar.
    <hr>
    I hope that solved your problem!
    <i>If it did, would you please choose this answer as your solution? It would help other Firefox users to find help on the forums faster and more efficiently. Thanks!</i>
    And of course, feel free to post back if you need more help!
    Happy browsing!

  • SQL Query to find Discoverer version installed

    Hi ,
    As a developer, Is there a back-end DB sql query (or script) that can be run on DB to find the version of Oracle Discoverer installed?
    Will the query be different if Discoverer is used with Oracle Applications (R12.1.3) as compared to a Discoverer running on a plain stand alone Oracle Database (no Oracle apps)?
    thanks,
    gg.

    Hello gg
    The VER_NAME and VER_DESCRIPTION are typically never filled in and can be ignnored.
    The VER_RELEASE is the EUL version as you rightly summised. This version is 100% compatible with Discoverer 11g and if you already have it you can upgrade from 10g to 11g without changing anything in the EUL
    VER_MIN_CODE_VER is the minimum version of Oracle Discoverer that can be used with this EUL. In this case 10.1.2.45.20 is 10g Release 2
    VER_EUL_TIMESTAMP is the date and time this version of the EUL was released by Oracle - again you can ignore it
    The important fields therefore are the VER_RELEASE and VER_MIN_CODE_VER
    Hope this helps
    Best wishes
    Michael

  • SQL Update a Single Row Multiple Times Using 2 Data Sets

    I'm working in tsql and have an issue where I need to do multiple updates to a single row based on multiple conditions. 
    By Rank_
    If the column is NULL I need it to update no matter what the Rank is.
    If the Ranks are the same I need it to update in order of T2_ID.
    And I need it to use the last updated output.
    I've tried using the update statement below but it only does the first update and the rest are ignored. Here is an example of the data sets i'm working w/ and the Desired results. Thanks in advance!
    update a
    set Middle = case when a.Rank_> b.Rank_ OR a.Middle IS NULL then ISNULL(b.Middle,a.Middle) end,
    LName = case when a.Rank_> b.Rank_ OR a.Lname IS NULL then ISNULL(b.LName,a.LName) end,
    Rank_ = case when a.Rank_> b.Rank_ then b.Rank_ end
    from #temp1 a
    inner join #temp2 b on a.fname = b.fname
    where b.T2_ID in (select top 100% T2_ID from #temp2 order by T2_ID asc)

    The Merge clause actually errors because it attempt to update the same record.  I think this CTE statement is the closest I've come but I'm still working through it as I'm not too familiar w/ them.  It returns multiple rows which I will have to
    insert into a temp table to update since the resulting row I need is the last in the table.
    ;WITH cteRowNumber
    AS(
    Select DISTINCT
    Row_Number() OVER(PARTITION BY a.LName ORDER BY a.LName ASC, a.Rank_ DESC,b.T2ID ASC) AS RowNumber
    ,a.FName
    ,a.LName
    ,b.LName as xLname
    ,a.MName
    ,b.MName AS xMName
    ,a.Rank_
    ,b.Rank_ AS xRank
    ,b.T2ID
    FROM #temp1 a
    inner join #temp2 b
    ON a.fname = b.fname
    ), cteCursor
    AS(
    Select a.RowNumber,
    a.Fname
    ,a.LName
    ,a.xLname
    ,a.MName
    ,a.xMName
    ,a.xRank
    ,a.T2ID
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xRank,a.Rank_) else ISNULL(a.Rank_,a.xRank) end AS Alt_Rank_
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xMName,a.MName) else ISNULL(a.MName,a.xMName) end AS Alt_MName
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xLName,a.lname) else ISNULL(a.LName,a.xlname) end as Alt_Lname
    FROM cteRowNumber a
    where a.RowNumber = 1
    UNION ALL
    Select crt.RowNumber
    ,crt.FName
    ,crt.LName
    ,crt.xLname
    ,crt.MName
    ,crt.xMName
    ,crt.xRank
    ,crt.T2ID
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xRank,Prev.Alt_Rank_) else ISNULL(Prev.Alt_Rank_,crt.xRank) end AS Alt_Rank
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xMName,Prev.Alt_MName) else ISNULL(Prev.Alt_MName,crt.xMName) end AS Alt_MName
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xLName,Prev.Alt_Lname) else ISNULL(Prev.Alt_Lname,crt.xLName) end as Alt_Lname
    FROM cteCursor prev
    inner join cteRowNumber crt
    on prev.fname = crt.fname and prev.RowNumber + 1 = crt.RowNumber
    SELECT cte.*
    FROM cteCursor cte

  • How can I install multiple versions of Firfox, and block the older versions from updating while allowing one version to continue updating?

    I need to have several versions of FF installed for training and testing purposes, but I can't keep older versions from updating. All versions will auto-update regardless of setting auto-update to off or suggest.

    hello miklewis, you can try to use portable versions of older versions of the browser & set them to not update (those are not provided by mozilla directly): http://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./

  • Analyzer 7.2.5.5.19 JRE Compatability - Highest Version ???

    Have conflict in house with varying versions of JRE on user pcs when User does not have Admin rights to the PC. Problem made worse by multiple JRE's on PCs. Have installed 7.2.5.5.19 with JRE 1.4.2_12 which works OK in test but are wanting to minimise the conflicts with highest version possible. Analyzer.properties file shows 1.5.0_09.
    What is the highest version and range of versions of JRE anyone has installed ?

    I have seen higher versions of the JRE cause Analyzer to perform slowly or strangely. I found that with Analyzer 7.2 that JRE 1.3.0_ actually performed the best.
    In System 9.3.0 I have been making all the clients use 1.5.0_11, when I installed 1.6 Analyzer began to have problems.
    Java is constantly improving so the latest seems like a good idea, but there's something in the Analyzer java applet (I think) that consistently needs updating when a new JRE is released.
    Brian Chow

  • What query should I use to find all versions of Office 2013 64-bit installed on client computers?

    What query should I use to find all versions of Office 2013 64-bit installed on client computers? Could someone create a custom query? I need all of the client computers names and which ones have any Office 64-bit components. Thank you so much! I really
    appreciate it!

    Hi,
    You could edit the following query to meet your requirement.
    SELECT     dbo.v_R_System.Name0, dbo.v_GS_OPERATING_SYSTEM.Caption0 AS [Operating System],
                          dbo.v_GS_OPERATING_SYSTEM.CSDVersion0 AS [OS Service Pack], arp.DisplayName0,
                          CASE WHEN arp.version0 LIKE '11.0.6361.0' THEN 'SP1' WHEN arp.version0 LIKE '11.0.7969.0' THEN 'SP2' WHEN arp.version0 LIKE '11.0.8173.0'
    THEN 'SP3' WHEN
                           arp.version0 LIKE '12.0.6215.1000' THEN 'SP1' WHEN arp.version0 LIKE '12.0.6425.1000' THEN 'SP2' WHEN arp.version0 LIKE '14.0.6029.1000'
    THEN 'SP1' ELSE '' END
                           AS 'Service Pack', arp.Version0
    FROM         dbo.v_Add_Remove_Programs AS arp INNER JOIN
                          dbo.v_R_System ON arp.ResourceID = dbo.v_R_System.ResourceID INNER JOIN
                          dbo.v_RA_System_SMSInstalledSites AS ASSG ON dbo.v_R_System.ResourceID = ASSG.ResourceID INNER JOIN
                          dbo.v_GS_OPERATING_SYSTEM ON dbo.v_R_System.ResourceID = dbo.v_GS_OPERATING_SYSTEM.ResourceID
    WHERE     (arp.DisplayName0 LIKE '%Microsoft Office%edition%' OR
                          arp.DisplayName0 LIKE '%Microsoft Office Standard 2007%' OR
                          arp.DisplayName0 LIKE '%Microsoft Office Enterprise 2007%' OR
                          arp.DisplayName0 LIKE '%Microsoft Office Professional%2007%' OR
                          arp.DisplayName0 LIKE '%Microsoft Office Standard 2010%' OR
                          arp.DisplayName0 LIKE '%Microsoft Office Enterprise 2010%' OR
                          arp.DisplayName0 LIKE '%Microsoft Office Professional%2010%' OR
                          arp.DisplayName0 LIKE 'Microsoft Office 2000%' OR
                          arp.DisplayName0 LIKE 'Microsoft Office XP%') AND (arp.DisplayName0 NOT LIKE '%update%') AND
                          (arp.DisplayName0 NOT LIKE '%Microsoft Office XP Web Components') AND (dbo.v_R_System.Operating_System_Name_and0 NOT LIKE '%server%')
    AND
                          (arp.InstallDate0 NOT LIKE 'NULL')
    ORDER BY dbo.v_R_System.Name0, arp.DisplayName0, arp.Version0
    Full details:http://social.technet.microsoft.com/Forums/systemcenter/en-US/7baeb348-fb63-4115-8d76-2c884d18f708/sql-query-to-check-ms-office-service-pack-level?forum=configmgrreporting
    Best Regards,
    Joyce
    We
    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.

  • Poll **IMPORTANT!** From wich Firmware version did you update your Zen XTRA. Was it succesf

    It's only a theory, but I guess the horror stories I've been reading about dead players after trying to update to the latest firmware has to do with the version you're updating from. Maybe I'm wrong, but we could make a statistic and try to find out if the success rate increases with any specific version.
    Maybe Cat could help and publish a Poll with multiple selection choices in stead of this thread? I would apreciate it very much!
    Best wishes
    Alen

    The MTP Protocol is the way that the PlaysForSure firmware communicates with your computer. Windows Media Player 0 is a big part of PlaysForSure/MTP. If you intend to use the PlaysForSure firmware then those 3 hotfixes should be applied, as they do improve Windows Media Player 0, but all other programs which will recognize your PlaysForSure player, such as Media Source, can perform better. If you are having problems transfering music with Media Source, then always try Windows Media Player 0 because if it doesn't work with WMP0, chances are it wont work with any other program. The other stuff listed, such as wdfmgr.exe and the registry changes are to help with the player being detected properly on your computer.
    Editing the registry can cause problems with your computer, however if you only edit that directory then you should be fine. In any case backing up your registry is recommended. For more on Registry Editing read this:
    <a href='http://support.microsoft.com/default.aspx?scid=kb;en-us;322756' target=_blank>http://support.microsoft.com/default.aspx?scid=kb;en-us;322756[/url]
    But do download those 3 hotfixes, and check for wdfmgr.exe, and also do the registry changes. If none of those are working then you might need to send your player in to Creative...

Maybe you are looking for

  • Sent mail is not being received

    Some of my emails use my me.com account are not being received by the recipient. The emails show being SENT in my SENT box.

  • Setting zoom

    How do I set the zoom, to stay on each time a new page reloads? i know that "command +" zooms in, but how do i make it stay that way?

  • Log-In Using Wireless Phone Number

    I "normally" log in to my accounts through My Verizon. This USED to give me access to BOTH my wireless and my residential (FiOS) accounts. Now, when I log in through My Verizon, I can access my wireless account, but when I try to access my residentia

  • Form routine problem

    what is the exact use of the form routine assigned in nace? eg: o/p type                                     script drv prog   form routine  formname NEU        (Purchase order)     SAPFM06P     ENTRY_NEU     MEDRUCK if i create any modifications in

  • I have been spending three days trying to move iTunes to a new PC

    I can move the music, the apps, everything, but what I want is to move that entire instance of itunes that recognizes my iPhone 5 (and my ipad, and my wife's ipad, and my wife and kids iphones) and make it be on the new PC so I can throw the old one