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

  • SEARCH
  • Home
  • 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 7657451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:02:12+00:00 2026-05-31T13:02:12+00:00

Return only records where there is a difference in FTE or Position title field.

  • 0

Return only records where there is a difference in FTE or Position title field.

I have a table of employee data with fields employee#, job#, start date FTE and Position. For each employee and job I only want to return records where there is a change in FTE or Position

Record,Employee#,Job#,Start Date,   FTE,Position  
1,     1000,    01, 01/01/2011, 100,    A  
2,     1000,    01, 01/06/2011, 100,    A  
3,     1000,    01, 01/07/2011, 80,     B  
4,     1000,    01, 01/08/2011, 80,     C  
5,     1000,    01, 01/10/2011, 80,     C  
6,     1000,    02, 01/01/2011, 20,     A  
7,     1000,    02, 01/05/2011, 20,     A  
8,     1000,    02, 01/08/2011, 20,     B   

The query should return records 1, 3,4,6,8. (These are the only records were FTE and Position are different from the previous row)

  • 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-31T13:02:13+00:00Added an answer on May 31, 2026 at 1:02 pm

    Depends on what database you are using. If youre using Oracle the the following should do the trick:

    SELECT *
    FROM (
      SELECT
        record
      , employee#
      , job#
      , start_date
      , fte
      , LAG(fte) OVER (ORDER BY record) previous_row_fte
      , position
      , LAG(position) OVER (ORDER BY record) previous_row_position
      FROM scott.stack_overflow_employee
    )
    WHERE fte != previous_row_fte
    OR position != previous_row_position
    OR previous_row_fte IS NULL
    OR previous_row_position IS NULL
    

    In the sub-query you can see the use of the Oracle analytical function LAG – A good article on this can be found here. This function is ordering the rows by ‘record’ and then selecting the previous rows fte or position. In the outer query the WHERE clause is specifying conditions to only return the row if the current fte is not equal to the previous rows fte or the same with position. In addition, due to the way oracle treats NULL values, additional conditions in the WHERE clause also return the row if either value are NULL.

    Whilst I have provided a solution, I must question why you are doing this, if given more information there is probably a better way to satisfy your solution, returning every row where there is a change seems like it might be leading on to bigger things. If you can provide more information as to what you are doing then maybe a better solution can be reached.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two employee lists that I want to get only unique records from
Working with the following code, I need to return only records where the `point'
The java.net.InetAddress.GetByName(String host) method can only return A records so to lookup other record
Anyone have any idea why shuffle() would only return 1 item? when using: $array2
Say that I have a table with a bunch of records, which I want
I have a large table with 1 million+ records. Unfortunately, the person who created
Is it possible to have named_scope return records unique for a certain column? e.g
I am trying to write a query that will return records where the field
I have 2 sets of data from different systems. About 20,000 records a piece.
I want to run a basic query, but return only the first ten rows

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.