Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Because of name changes I have multiple records for the same employee in my table. I went to retrieve the last changed record. The only column I have that may be of help is LastChangedDate. Is there a way to retrieve a record from this table where the last changed date is the most current? I would appreciate any help. THANK YOU!!!!!!
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2002-11-07 : 16:31:17
This should do it for you:SELECT MAX(LastChangedDate)FROM Table1WHERE Last_name = 'Smith' and First_name = 'John'Just change the table name and the where clause to get the correct record.Edited by - tduggan on 11/07/2002 16:32:06
r937
Posting Yak Master
112 Posts
Posted - 2002-11-07 : 19:23:06
if there's more than one employee with multiple records, use a correlated subquery
select EmployeePK, Firstname, Lastname , LastChangedDate from yourtable A where LastChangedDate = ( select max(LastChangedDate) from yourtable where EmployeePK = A.EmployeePK )