Remove the duplicate rows but keep the most recent and oldest records

I have a Product table, some products have duplicate rows(same productID). I want to keep the most recent and the oldest records based on ETL load date (or min and max productKey), delete others. How to do this in a simple way?
ProductKey | ProductID |ETL_Load_Date
1001 | 501 | 2014-01-01
1002 | 501 | 2014-01-02
1003 | 501 | 2014-01-03
1011 | 502 | 2014-01-01
1012 | 502 | 2014-01-02
1013 | 502 | 2014-01-03

declare @table table (ProductKey int, ProductID int, ETL_Load_Date date)
insert @table (ProductKey, ProductID, ETL_Load_Date)
values
( 1001 , 501 , '2014-01-01' ), ( 1002 , 501 , '2014-01-02' ),
( 1003 , 501 , '2014-01-03' ), ( 1011 , 502 , '2014-01-01' ),
( 1012 , 502 , '2014-01-02' ), ( 1013 , 502 , '2014-01-03' )
SELECT *
FROM @table t
INNER JOIN (
SELECT MIN(etl_load_date) min_load_date, MAX(etl_load_date) max_load_date, ProductID
FROM @table
GROUP BY ProductID
) m
ON t.ProductID = m.ProductID
AND t.ETL_Load_Date IN (min_load_date,max_load_date)
This will show both the min and max load dates, for each ProductID
Thanks to Saeid for posting some test objects.

Similar Messages

  • How do I delete duplicate songs, but keep a link in their original albums to the single copy of the song left, so it will play in each album in sequence as if it were still there?

    Greetings!
    After importing my 300 or so CDs into iTunes, I found I have tons of duplicate songs.
    Example: I have a song that came in a original album, then in again in a "Greatest Hits" album, then again in a "Hits of the 80's" album, and again in a soundtrack album. I have now have 4 copies of the exact same song.
    How do I delete duplicate songs, but keep a link in their original albums back to the single copy of the song left, so it will play in each album in sequence as if it were still there?
    I don't think this currently exists, but as my library keeps growing the duplicates keep growing.  It would be nice if Apple sees this and adds a way to link songs to multiple albums.
    I don't want to create a custom playlist for every album that has a duplicate song or two (I'd have dozens of playlists) - thought about fixing it that way but not really practical.

    To my knowledge, there is no way of doing what you want. The only workaround is to create playlists for the other albums containing the track, but that isn't practical for most people.
    You could provide Apple with feedback here: http://www.apple.com/feedback/itunesapp.html

  • How do I get the numbers ipad app to plot a graph of dates against values, where the most recent date is on the right of the graph, but the most recent date is at the top rather than bottom of the rows in the table?

    How do I get the numbers ipad app to plot a graph of dates against values, where the most recent date is on the right of the graph, but the most recent date is at the top rather than bottom of the rows in the table?
    Also how can it be a line graph without plotting a circle at each value?
    Thanks this is very frustrating

    Make a copy of the table and produce your Line chart or Bar chart from the copy. Sort the copy into the order you want to see in your chart.
    Alternately you could use a Scatter Chart...
    Jerry

  • Opening since update to Firefox 6, always get the message that I don't have the most recent version - have removed and reinstalled, but still persists.

    I recently updated my Firefox to version 6.0. When it re-opened after installation there was a message that I didn't have the most recent version. I ran the update set-up again but got the same message. I uninstalled Firefox and reinstalled it from a fresh download but it's still happening.
    I've restarted the computer several times. It doesn't seem to have helped. Any ideas?

    * Download a new copy of the Firefox program: http://www.mozilla.com/firefox/all.html
    * Trash the current Firefox application to do a clean (re)install.
    * Install the new version that you have downloaded.
    Your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks and other personal data.

  • I have a 1st Gen Time Capsule 1tb. It turns on, boots up and turns green for 5-10 mins, but then turns solid orange and then blinks orange.  I have removed the hard drive and replaced the power supply . . . still the same problem.  Suggestions?

    I purchased a used 1st Gen Time Capsule with a 1 tb hard drive.
    When I plugged it in and did the initial setup, it worked fine, but gave me a hard drive error.  A few minutes later the green light turned solid orange, then blinking orange, then the status light went off.  The lights in back stayed on. 
    I removed the hard drive and rebooted, it turned green for 5-10 minutes then reverted back to a solid orange, blinking orange, then went off.
    Next I purchased a remanufactured internal power supply, and installed it (without the hard drive in).  It turned green almost immediately.  After about 15-20 minutes, I decided to try to install the hard drive again, booted it up, and tried to erase the hard drive with was working properly according to the software.  It stopped erasing the disc after about 20 minutes and turned solid orange again, then blinking, then no status light  (but back lights were still lit).
    I'm a bit flabbergasted at this point, any suggestions on what to do next?  I think i've pretty much replaced everything except the logic board, but can't seem to find any information on the symptoms of a logic board malfunction. 
    Thanks!!!!!!!

    A Gen3 is identical board to a Gen4 although they have some differences in firmware and wireless card was updated on every model.. but a Gen3 is substantially faster than Gen1, Gen2 which also have identical boards.
    You can with careful shopping get a Gen3 pretty cheap.
    Most use a delta power supply which I think is a lot better than the flextronics used in most Gen1/2
    You can sell back the parts to ebay.. people still would buy the power supply etc. Even just the case can be useful to a repairer.
    But if the board is gone.. it is hard to repair.. not impossible.. but hard.
    Gen 3 and Gen 4 are not without faults.
    See this page.
    https://sites.google.com/site/lapastenague/a-deconstruction-of-routers-and-modem s/apple-time-capsule-repair/new-issue-with-a1355-gen-3-tc
    I have fixed it a different way.. by using the small converters you can buy in bulk from ebay for $1 each.. KIS3R33 .. they produce 3.3V at 2A peaking at 3A.. amazing.. I keep using them to replace onboard power converters by removing the inductor and simply power directly.. the end result has worked great. You can simply change the resistors around and get any output from 1v to 20v depending on input.
    Is it worth doing it .. no of course not.. it will waste many more hours than $50 is worth.. but it is kind of fun that you can actually make things work again.
    Here is a pic of the Gen 3 totally powered by me. All onboard power removed.
    This was to track down the fault in the Gen3.. but I am kind of pleased that it ended up neat enough and reliable enough to work for more than a year.. the Gen3 still serves as a way to get Netflix via network for a friend running 24/7.
    The units supply (from left to right)
    1v, 1.1v, 3.3v, 5v, 1.8v
    It is feed by 12v supply which is also directly connected to the hard disk.
    So it is possible to fix.. !! Only got to be a bit crazy.

  • Firefox has suddenly gone wrong. I was successfully running both Firefox and Internet Explorer 8 on Windows 7. I auto-accept upgrades including the most recent Firefox upgrade and the suggested upgrade to Adobe Flash 10.1. But after this, Firefox stopped

    Firefox has suddenly gone wrong. I was successfully running both Firefox and Internet Explorer 8 on Windows 7. My laptop is new and has plenty of RAM and HDD. I auto-accept upgrades including the most recent Firefox upgrade and the suggested upgrade to Adobe Flash 10.1. But after this, Firefox stopped working and does not work when I re-load Firefox 3.6. Also IE8 now works very slowly and does not locate major websites like Microsoft without a 'can't find the website message' and having to pressing Return a second time. When I do get to the Mozilla website and click on the button to try to download Firefox 3.6.6, I get this message "Oops! Internet Explorer could not find mozilla3.snt.utwente.nl". Can you help with what has gone wrong? As it stands, I can't use Firefox at all. Note: because Firefox did not work after the upgrade, I've downloaded the IE8 version of the Adobe Flash 10.1. What I really want is to be able to use both Firefox and IE8. But is this possible if they use different versions of Adobe Flash?
    == This happened ==
    Every time Firefox opened
    == About 2-3 days ago ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.5; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET4.0C)

    I have been having the same problem as the original poster. After upgrading to Ffx 3.6.6, the program asks you to upgrade to Flash Player Plugin 10.1. I download and installed 10.1 only to find videos weren't loading.
    In my case, the problem is the previous installation of Flash Player (9.0.47) was somehow messing things up. To fix this, because I already had Flash plugin 10.1 installed I had to uninstall 10.1 using the uninstaller from adobe and then manually remove any files related the old flash player plugin 9.0.47
    Here is a run-down of my process:
    0. To check if you have a previous installation of the Flash Plugin lurking around, in Firefox go to Tools -> Add-ons -> Plugins (tab). At this point you may seen both Flash plugins.
    1. Proceed to uninstall Flash Plugin 10.1. Adobe provides an uninstaller here: http://kb2.adobe.com/cps/141/tn_14157.html
    ( you have to make sure you have nothing running when you execute the installer).
    2. On my Mac (sorry I don't know what it is in Windows) I searched the hard drive for any files/folders with "Shockwave". I found a folder called "Shockwave 10". It wasn't removed by Adobe's uninstaller. For safety I deleted it and then emptied the trash.
    3. I then went to My HD -> Library -> Internet Plugins.
    Remove the file and folder named "Flash player.old"
    4. Restarted; ran the Adobe Flash Player 10.1 installer. Restarted again.
    5. Opened up ffx and double checked the plugins list (see step 1). Version 10.1 is installed and available. Went to problem sites to test it out and Success!
    Hope this helps.

  • I tried to update to the most recent itunes, but the update failed and now when I try to open itunes a dialog box pops up and tells me that it can.t open because MSVCR80.dll is missing.  I need help!

    I tried to update to the most recent version of itunes but the update failed.  Now when I try to open itunes I get a dialog box telling me it can,t open because MSVCR80.dll is missing.  I tried uninstalling and reinstalling itunes but I grt the same message.  What can I do to fix this?

    Solving MSVCR80 issue and Windows iTunes install issues.
    Thanks to user turingtest2 for this solution.
    Solving MSVCR80 issue and Windows iTunes install issues.
    If the above doesn’t do the trick entirely, then use the instructions in the following as it applies to the version of Windows you are using:
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    You may be required to boot into safe mode to complete the folder deletion process.

  • Hi, I have a late 2011 MacBook Pro but cant get the mirroring function to work with Apple TV.  I've got the most recent Software 10.7.5 but cant see the mirroring icon or turn this on.  I'm able to mirror from my Ipad but not my Mac, any thoughts?

    Hi, I have a late 2011 MacBook Pro but cant get the mirroring function to work with Apple TV.  I've got the most recent Software 10.7.5 but cant see the mirroring icon or turn this on.  I'm able to mirror from my Ipad but not my Mac, any thoughts?

    Welcome to the Apple Support Communities
    AirPlay Mirroring is supported on your Mac, but it needs OS X Mountain Lion (10.8). See > http://support.apple.com/kb/HT5404
    You have two possibilities:
    1. Make a backup, open App Store and purchase Mountain Lion to upgrade to this OS X. Then, you will find the AirPlay Mirroring icon at the top right of the display, on the menu bar, or on System Preferences > Displays.
    2. Keep OS X Lion and use AirParrot > http://www.airparrot.com
    Both options work properly, but I recommend AirPlay Mirroring as it doesn't need a third-party program

  • I have downloaded the most recent itunes on my new computer with windows 8        but a message pops up saying "the itunes library.itl file is locked, on a locked disk or you do not have write permission for this file. How do I fix?

    I have downloaded the most recent itunes on my new computer with windows 8 but when I attempt to get in I get this message "The itunes library.itl file is locked, ona locked disk, or you do not have write permission for this file."  How do i fix this?

    Repair iTunes Security Permissions
    Right-click on your main iTunes folder and click Properties, then go to the Securitytab and click Advanced. Use the Change Permissions... button grant to your account (or the Users group) and SYSTEM full control of this folder, subfolders and files, then tick the option to Replace permissions entries... which will repair permissions throughout the library. When complete switch to the General tab, click in the Read-only check box to clear it, then click Apply.
    If you don't have the option to change the permissions then use the Owner tab and Edit... button to take ownership from an account with administrator privileges. Tick the option to Replace owner on subcontainers and objects.
    Repeat with the media folder if it isn't stored inside the main iTunes folder.
    If you've brought over the library from another computer you may also want to remove any "mystery" identities (S<string of dashes & digts>) that have come over from the old computer...
    The images above are from Windows 7. Hopefully the system isn't too different in Windows 8.
    tt2

  • I have a Mac and I have downloaded the most recent Adobe Acrobat, but files will not open.  Any suggestions?

    I have a Mac and downloaded the most recent Adobe Acrobat version, in order to open PDF's on a site I use.  They changed something recently and advised everyone to get up to date, which I did, but to no avail.  I keep getting a "waiting" message. I have used the Safari "develop" menu to simulate Internet Explorer, but with no luck.
    Any suggestions?

    Please wait...
    If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be able to display this type of document.
    You can upgrade to the latest version of Adobe Reader for Windows®, Mac, or Linux® by visiting http://www.adobe.com/go/reader_download.
    For more assistance with Adobe Reader visit http://www.adobe.com/go/acrreader.

  • How to return only the most recent row?

    Hi guys,
    I have a question which I am hoping is not too difficult but I just am not sure how to do it. I need to run a query on a table which may bring back multiple rows for my criteria, however I only want to bring back 1 of these multiple rows and the one I want to bring back has to be the most recent. I do have a date_created column on my table as well as a date_last_updated column. So basically using the select statement below as an example this query could return lets say 5 rows, I however only want it to return the most recent row and the most recent row is determined by the date_last_updated (which will only be populated if the record has been updated otherwise it is null) or the date_created fields.
    select * from my_table
    where model_id = 234
    Any help on this matter would be greatly appreciated.
    Thank you.

    Hi,
    you can do; -
    select *
    from
    (select *
    from my_table
    order by creation_date desc)
    where rownum = 1This does not guarantee that you will get the most recent in cases of records being created at exactly the same time, but if your table has a prime key then you could use this as the order by to get the same effect, though if say 5 records are inserted as a batch what does it really mean to be inserted last....
    regards,
    Robert.
    Edited by: Robert Angel on 09-Jul-2012 08:22 to add code tags.

  • Highlighting the most recent date in a row

    hi all
    I have a series of 5 dates in a row. I would like to be able to highlight only the cell containing the most recent date (in respect to the current date) in each row.
    There will be instances when there is no date in some of the cells.
    Thanks for the help in the past, this and the other forums are awesome.

    Jason is correct. It requires two tables.
    I had started experimenting with this last night, but an outage at my ISP prevented posting at that time.
    Conditional formatting of a cell depends on comparing the value in that cell with a fixed value contained in the rule; the rule itself cannot reference a different cell to pick up the comparison value. So you need to calculate a value in a cell on a second table, apply conditional formatting to that cell, and place it directly behind the cell containing the date to be highlighted.
    Example:
    Dates are in cells B7 to F7 of Table 1
    Cell H1 is used to select the maximum date.
    Table 2 is a single row table with no row or column header cells, and only 5 columns.
    Select Table 1, open the Inspector, and use the Table inspector to set Cell Background to “None”
    In Cell H1 enter: =MAX(B7:F7)
    Go Insert > Table > Plain
    Resize the new table (Table 2) to 1 row x 5 columns.
    In A1 of Table 2, enter: =DATEDIF(Table 1::B7,Table 1::$H7,"D")
    Drag the handle at the lower right of the cell to copy the formula into all five cells.
    Click on A1.
    Open the Inspector and choose the Cell Format inspector.
    Check the Conditional Format checkbox, then click Show rules...
    Set the rule to “Equal to... 0”
    Choose a Fill colour to serve as your highlight colour.
    Click on the next cell and repeat.
    When you have applied the rule to all five cells, close the Conditional Format dialogue.
    Choose all five cells. Open the Text inspector.
    Click on the colour well.
    Leave the text colour set at Black, but move the Opacity slider to 0%.
    Close the Inspector and the Colors dialogue.
    Select Table 2 and drag it into position covering the five cells with dates on Table 1. Use the Arrow keys to nudge it into exact alignment.
    Go Arrange > Send Backward to move Table 2 behind Table 1. Repeat until you can see the dates on Table 1.
    Regards,
    Barry

  • I just found my old ipod touch (i think 1st generation) and would like to let my toddler use it instead of my phone.  I am trying to download apps but it say I need to update to 4.3 but it won't let me update.  I have the most recent itunes. any idea why?

    I just found my old ipod touch (i think 1st generation) and would like to let my toddler use it instead of my phone.  I am trying to download apps but it say I need to update to 4.3 but it won't let me update.  I have the most recent itunes. any idea why? I saw a thread saying to purchase the newest software (that was posted a few years ago) I paid 4.95 for the software and it's still saying it can't be updated.  Am I just SOL??

    The 1G iPod can only go as high as 3.1.3. The 1G does not have an internal speaker or volume buttons on the upper left edge.
    Identifying iPod models
    To more easily find compatible apps:
    iOSSearch - search the iTunes store for compatible apps.
    Apple Club - filter apps by iOS version.

  • Why is it that when I go to the search screen to find a particular message in a conversation it comes up with the message but when I click on it it takes me to the conversation where the most recent message was sent and not the message I wanted

    Why is it that when I go to the search screen and type in a particular message I want to view, my iPhone finds it but when I click on it it only takes me to the conversation at the most recently thing texted and not the particular message I clicked on?

    Never occurred to me you can search messages that way, thanks.
    Another way to do it is to scroll from the most recent message to the top of the screen and tap load more messages, repeatedly till you reach the one you want.
      I like your method better, but with both methods it refreshes to the most recent message.

  • SSRS 2008 R2 is extremely slow. The query runs in less than a second in the dataset designer but if you try to view the report it takes over 10 minutes. I have read this is a bug in SSRS 2008 R2. We installed the most recent patches and service packs.

    SSRS 2008 R2 is extremely slow.  The query runs in less than a second in the dataset designer but if you try to view the report it takes over 10 minutes.  I have read this is a bug in SSRS 2008 R2.  We installed the most recent patches and
    service packs.  Nothing we've done so far has fixed it and I see that I'm not the only person with this problem.  However I don't see any answers either.

    Hi Kim Sharp,
    According to your description that when you view the report it is extremely slow in SSRS 2008 R2 but it is very fast when execute the query in dataset designer, right?
    I have tested on my local environment and can‘t reproduce the issue. Obviously, it is the performance issue, rendering performance can be affected by a combination of factors that include hardware, number of concurrent users accessing reports, the amount
    of data in a report, design of the report, and output format. If you have parameters in your report which contains many values in the list, the bad performance as you mentioned is an known issue on 2008 R2 and already have the hotfix:
    http://support.microsoft.com/kb/2276203
    Any issue after applying the update, I recommend you that submit a feedback at https://connect.microsoft.com/SQLServer/ 
    If you don’t have, you can do some action to improve the performance when designing the report. Because how you create and update reports affects how fast the report renders.
    Actually, the Report Server ExecutionLog2  view contains reports performance data. You could make use of below query to see where the report processing time is being spent:
    After you determine whether the delay time is in data retrieval, report processing, or report rendering:
    use ReportServer
    SELECT TOP 10 ReportPath,parameters,
    TimeDataRetrieval + TimeProcessing + TimeRendering as [total time],
    TimeDataRetrieval, TimeProcessing, TimeRendering,
    ByteCount, [RowCount],Source, AdditionalInfo
    FROM ExecutionLog2
    ORDER BY Timestart DESC
    Use below methods to help troubleshoot issues according to the above query result :
    Troubleshooting Reports: Report Performance
    Besides this, you could also follow these articles for more information about this issue:
    Report Server Catalog Best Practices
    Performance, Snapshots, Caching (Reporting Services)
    Similar thread for your reference:
    SSRS slow
    Any problem, please feel free to ask
    Regards
    Vicky Liu

Maybe you are looking for

  • Can not transfer the partner data from ROS to EBP

    Hi, All We are using SRM 5.0, and setup the ROS ans SUS in one client, EBP in another client. All the configuration was done, we maintained the table: BBP_MARKETP_INFO by SM30 with the following record: COMPANY_ROOT   VENDOR_ROOT    DUMMY_EKORG    US

  • How to match the width of the choice box's dropdown to the choice box

    Hi there, I'm using a ChoiceBox control. The choice box seems to be composed of two parts: the box(displaying the current selection) and a context menu(dropdown). What I find strange is that the dropdown of the choice box(the context menu) has differ

  • Forcing a User to enter Data

    I have a Designer 7 form where every field must be filled and the user must not go on to the next field until the current one is completed. In Designer 5 the following 'OnExit' script would always set focus to the required field no matter what the us

  • Problems freeing up memory

    i've been having a problem of late with my iPhone 5s 16 GB. I have been receiving a warning box, advising me that my memory is low; problem is, no matter how many apps I delete, I'm still advised that I have no memory available despite the fact that

  • Company description in DTA file for automatic payment

    Hi all I have changed the description of my company in customizing (T001). When i generate the DTA file after the payment generation (F110), the company description is still the old name. Where i must change? thanks Davide