We help IT Professionals succeed at work.

get only first row

Here  is some sample data from a table I have named EmployeeLoungeVisits

EmployeeID   VisitDate
1234                01/02/13
1234                02/01/12
1234                03/23/14
2333                12/20/14
2333                07/02/14


I am trying to write a query that will return only the employee id with the latest vist date


Using the example data above, looking for the following result set
 
EmployeeID   VisitDate
1234                03/23/14
2333                12/20/14
Comment
Watch Question

Developer Analyst
Commented:
CREATE TABLE #Employees 
( 
    EmployeeID INT, 
    VisitDate Datetime 
)

INSERT #Employees(EmployeeID,VisitDate) VALUES('1234','01/02/13') 
INSERT #Employees(EmployeeID,VisitDate) VALUES('1234','02/01/12') 
INSERT #Employees(EmployeeID,VisitDate) VALUES('1234','03/23/14') 
INSERT #Employees(EmployeeID,VisitDate) VALUES('2333','12/20/14') 
INSERT #Employees(EmployeeID,VisitDate) VALUES('2333','12/20/14') 

select employeeID,Max(VisitDate) from #Employees
group by employeeID

Open in new window

Author

Commented:
Thanks!