Guru E. Technology

need of every business.


How to Get Unique Item with Latest Date of Entry

Situation is, I have a table which contains multiple records of a item but with different date. For example, I have table of workers which contains the Id, Name, WorkingDay column similar to below table:

ID NAME WorkingDay
1 VJ 15-Mar-2012
2 AP 15-Mar-2012
3 TS 15-Mar-2012
1 VJ 16-Mar-2012
2 AP 17-Mar-2012

I want to get the latest record of each worker. Following is the query:

select * from WorkingDetails wd
WHERE WorkingDay=(SELECT MAX (WorkingDay) FROM WorkingDetails WHERE ID=wd.ID);

It will return the output:

ID NAME WorkingDay
1 VJ 16-Mar-2012
2 AP 17-Mar-2012
3 TS 15-Mar-2012

I hope it would be helpful, please comment if you like this post.

Tags: , ,

Posted in SQL Server


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>