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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query

Status
Not open for further replies.
Feb 17, 2005
23
US
Employee_ID SOP_ID SOPCode Training_Date Rev
96 3 TP0 03/05/2003 0
96 3 TP0 04/05/2004 0
96 6 TP0 04/03/2005 1
96 7 TP0 NULL 2
96 83 TM0 04/03/2005 0

Can anyone help me with this query
how to get a output like this

96 7 TP0 NULL 2
96 83 TM0 04/03/2005 0

I need to get the latest training date of all the same SOPCodes even when the rev is different or it could be null.

this is the original thread for it but couldnt get the answer.

pls thanks

 
Try this:
Code:
SELECT A.Employee_ID,A.Sop_ID,
       A.SOPCode, A.Training_Date,
       A.Rev
FROM mytable A WHERE
A.Training_Date IN (
SELECT TOP 1 Training_Date FROM mytable B
WHERE A.SOPCode=B.SopCode
ORDER BY Training_Date DESC
)

-DNG
 
thanks for ur help. didnt work.
I tried that query

I get this result

96 3 TP0 04/05/2004 0
96 6 TP0 04/03/2005 1
96 7 TP0 NULL 2
96 83 TM0 04/03/2005 0

Even thought SOP_ID are different for 3 and 6 the r same. They r revised.

I need this
96 7 TP0 NULL 2
96 83 TM0 04/03/2005 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top