Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Max query

Author  Topic 

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-04-09 : 13:51:14
I need a query help in getting the results:

EmpNo Empdate
----- ----------
01 06/23/2006
01 06/28/2006
02 03/24/2006
03 05/21/2006
03 06/24/2006
04 09/27/2006

Output:

EmpNo Empdate
----- ----------
01 06/28/2006
02 03/24/2006
03 06/24/2006
04 09/27/2006

spejbl
Starting Member

28 Posts

Posted - 2007-04-09 : 13:57:02
[code]SELECT
EmpNo, MAX(Empdate)
FROM dbo.YourTable
GROUP BY EmpNo
ORDER BY EmpNo[/code]--
Tom
Microsoft KB articles monitoring
Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-04-09 : 14:46:50
Thanks !!
Incase of having nulls in the table how to rewrite the query

EmpNo Empdate
----- ----------
01 Null
01 06/28/2006
02 03/24/2006
03 Null
03 06/24/2006
04 09/27/2006

Output:

EmpNo Empdate
----- ----------
01 06/28/2006
02 03/24/2006
03 06/24/2006
04 09/27/2006
Go to Top of Page

spejbl
Starting Member

28 Posts

Posted - 2007-04-09 : 14:51:44
[code]SELECT
EmpNo, MAX(Empdate)
FROM dbo.YourTable
WHERE Empdate IS NOT NULL
GROUP BY EmpNo
ORDER BY EmpNo[/code]--
Tom
Microsoft KB articles monitoring
Go to Top of Page
   

- Advertisement -