I have table like below
ID User Date Location
1 Tom 6-Mar-2012 US
2 Tom 4-Feb-2012 UK
3 Tom 6-Jan-2012 Uk
4 Bob 6-Mar-2012 UK
5 Bob 4-Feb-2012 UK
6 Bob 6-Jan-2012 AUS
7 Dev 6-Mar-2012 US
8 Dev 4-Feb-2012 AUS
9 Nic 6-Jan-2012 US
I have to get each employee recent location in same table.
ID User Date Location CurrentLocation
1 Tom 6-Mar-2012 US US
2 Tom 4-Feb-2012 UK US
3 Tom 6-Jan-2012 Uk US
4 Bob 6-Mar-2012 UK UK
5 Bob 4-Feb-2012 UK UK
6 Bob 6-Jan-2012 AUS UK
7 Dev 6-Mar-2012 US US
8 Dev 4-Feb-2012 AUS US
9 Nic 6-Jan-2012 US US
I have tired with temp tables. can I get this done using single query. This is in middle of implementation. I have already created many temp tables.
Thanks in Advance.
Try this:
Output:
Live test: http://www.sqlfiddle.com/#!3/83a6a/7