Click here to Skip to main content
15,894,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I have an table named Courier_Tracking that track all updation of courier table

Courier_Tracking table structure


Courierid UpdationDate Status
1 2014-07-25 15:58:37.813 Delivered
1 2014-07-25 12:58:37.813 In Process
2 2014-07-25 15:58:37.813 Delivered
2 2014-07-25 12:58:37.813 In Process
3 2014-07-25 15:58:37.813 Delivered
3 2014-07-25 12:58:37.813 In Process
4 2014-07-24 15:58:37.813 Delivered
4 2014-07-24 12:58:37.813 In Process
5 2014-07-24 15:58:37.813 Delivered
6 2014-07-24 12:58:37.813 In Process


Now i want to show only final changes(most recent one) from this on daily basis for every courierid like this


Courierid UpdationDate Status
1 2014-07-25 15:58:37.813 Delivered
2 2014-07-25 15:58:37.813 Delivered
3 2014-07-25 15:58:37.813 Delivered
4 2014-07-24 15:58:37.813 Delivered
5 2014-07-24 15:58:37.813 Delivered

I have no idea how to do it .
Please help me.Thanks in advance guys.
Posted
Updated 25-Jul-14 2:11am
v2

1 solution

The constructs you need are GROUP BY[^]
which means you can then use the MAX[^] function

Hint: If you were to add some additional data for one of the couriers e.g.
insert into Courier_tracking values( 1, '2014-07-26 12:18:37.813', 'In Process')
you can check for the requirement you mentioned "daily basis" if you look up CAST[^]E.g.
CAST(UpdationDate as date)
will help you get daily results such as
1 2014-07-25 July, 25 2014 15:58:37+0000 
1 2014-07-26 July, 26 2014 12:18:37+0000 
I'm not going to give you much more as this looks like homework. Have a go and come back if you get into difficulty
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900