SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query to retrive the most recent record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vishnu Rajendran
Starting Member

India
1 Posts

Posted - 06/17/2013 :  06:14:59  Show Profile  Reply with Quote
I have a 'emloyeeeducation' table where the education level of employees are captured.An employee can have many degrees like in BTech in 2007,MBA in 2011 .etc.My requirement is to show the 'Qualification' as the latest degree only,say here the qualification is MBA because it is the latest.It should be based on the year of passing.Please help me write the query.

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 06/17/2013 :  06:20:26  Show Profile  Reply with Quote

SELECT *
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY employeeid ORDER BY yearofpassing DESC) AS Seq,*
FROM employeeducation
)t
WHERE Seq=1


I've assumed columnnames based on your explanation so make sure you use correct columnnames instead if different from mine

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000