View Single Post
  #1 (permalink)  
Old April 12th, 2007, 11:29 AM
Nancy Krause Nancy Krause is offline
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL script for selecting min and max values

There is a table that has an effective date column and a sequence number column and an employee number. Each employee number may have multiple rows. Each employee's row has an effective date. Each employee's row has a sequence number. Each employee's row has a unique effective date and sequence number combination. The sequence number is automatically assigned when a row is inserted into the table starting with 999 for each employee and decreasing by one for each subsequent row that is inserted for the employee with the same effective date. I need to select one row for each employee that has the maximum effective date but the mininum sequence number by I haven't been able to successfully code it in SQL. Example of rows in the table:
employee number effective date sequence number
     00933 2007-03-01 999
     00933 2007-03-01 998
     00993 2007-02-15 999
     01689 2006-12-10 999
     71553 2007-01-03 999
     71553 2006-12-02 999
     71553 2006-12-02 998

After running this query, I'd expect to see
00933 2007-03-01 998
01689 2006-12-10 999
71553 2007-01-03 999

Reply With Quote