Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4122468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:29:07+00:00 2026-05-20T23:29:07+00:00

Ok. First let me apologize profusely if this question has been covered. I did

  • 0

Ok. First let me apologize profusely if this question has been covered. I did look but none of the solutions addressed the particulars of my problem.

I have a table of over 160 million rows of data tracking employee/server conditions over time. I want to create a subset of this data and remove the repetition that occurs throughout, BUT keeps the sequence of changes as they occur. The reduction for most employees would be from 700 rows (and growing) to 1.

Here’s a simplified example of what I’m trying to get to:

Given:

RowID  Employee  Server  Timestamp
-----  --------  ------  ---------
5      E000001   Serv-B  May01
4      E000001   Serv-A  Apr01
3      E000001   Serv-B  Mar01
2      E000001   Serv-A  Feb01
1      E000001   Serv-A  Jan01

Doing a "Min(Timestamp) Group By Employee, Server" would yield:
Employee Server  Timestamp
-------- ------  ---------
E000001  Serv-B  Mar01
E000001  Serv-A  Jan01
.
What I need is:
Employee Server  Timestamp
-------- ------  ---------
E000001  Serv-B  May01
E000001  Serv-A  Apr01
E000001  Serv-B  Mar01
E000001  Serv-A  Jan01

The table and the process that feeds it do not belong to our group so I can’t affect a solution there and I’d rather not be stuck with a copy of the entire thing. I can’t realistically do a cursor/RBAR approach given the size of the table. If backed into a corner, I can write an application program to do this but I was wondering if any of the gods from SQoLympus had any wisdom for doing this in a stored procedure. Thanks in advance!

Edit: It’s SQL Server 2008 – Sorry for not mentioning it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:29:08+00:00Added an answer on May 20, 2026 at 11:29 pm

    If SQL Server (assuming I have understood your requirements correctly)

    /*Set up test table*/
    DECLARE @T TABLE (
      RowID       INT,
      Employee    CHAR(7),
      [Server]    CHAR(6),
      [timestamp] DATETIME );
    
    INSERT INTO @T
    SELECT 5,'E000001','Serv-B',  '20010501' UNION ALL
    SELECT 4,'E000001','Serv-A',  '20010401' UNION ALL
    SELECT 3,'E000001','Serv-B',  '20010301' UNION ALL
    SELECT 2,'E000001','Serv-A',  '20010201' UNION ALL
    SELECT 1,'E000001','Serv-A',  '20010101';
    
    WITH cte
         As (SELECT ROW_NUMBER() OVER (PARTITION BY Employee ORDER BY RowID) -
                    ROW_NUMBER() OVER (PARTITION BY Employee, Server
                                           ORDER BY RowID) AS Grp,
                    *
             FROM   @T),
         cte2
         AS (SELECT *,
                    ROW_NUMBER() OVER (PARTITION BY Employee, Grp ORDER BY RowID) AS
                    Rn
             FROM   cte)
    
    /* Edit: Actually - You want a SELECT not a DELETE I think?
    DELETE FROM cte2 WHERE  Rn > 1*/
    
    SELECT   RowID, Employee, [Server], [timestamp]
    FROM cte2
    WHERE  Rn = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, let me apologize if this has been asked already, but I can’t
Let me first apologize if this question could sound perhaps sort of amateurish for
Let me first apologize. I've been coding for a long time now, but I'm
First let me say that I really feel directionless on this question. I am
Caveats: Let me first clarify that this is not a question about whether to
First off let me apologize to the SO community for coming to you with
I couldn't think of a decent title, so let me first apologize for that.
First of all let me say that this questions is slightly connected to another
First of all let me know if my question is completely vague or doesnt
First, let me apologize, I'm new at web development, so I'm not quite sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.