Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the result set from the table using a query. Enter to see the table and result set.

Status
Not open for further replies.

carolx

Programmer
Jul 22, 2003
75
JM
I need to display the last occurrences of Personid from the table using a query.


Table - ordered by employmentid
EmploymentId PersonId BranchId HireDate
12 23 24 2019-04-21
15 23 24 2019-06-21
18 23 24 2019-09-26
21 23 24 2019-10-05
22 17 24 2019-02-21
24 13 24 2019-02-21
25 13 24 2019-06-22
26 17 24 2019-04-11

Result Set
EmploymentId PersonId BranchId HireDate
21 23 24 2019-10-05
25 13 24 2019-06-22
26 17 24 2019-04-11

 
SELECT DISTINCT PERSONID,MAX(hiredate) AS hiredate FROM [Employment].[Employment] WHERE StatusTypeId = 3 group by personid ORDER BY hiredate DESC

Thanks for the suggestion. I added MAX(hiredate) with the GROUP BY clause.
 
You don't need DISTINCT here. GROUP BY gives you one record per PersonID.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top