sql query help getting the correct record

I have 2 table. 1 table keep all base files. The second table keep track of all uploaded files.

I need to pull only latest records for unique docKey.

In reality i need only record 2 and 3

The attached file has a screen shotscreen capture
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SELECT IM.docKey, MU.filename, IM.name, MU.uploadID, MU.UploadedWhen 
	InsManual IM WITH (NOLOCK) 
		FROM InsManualUploads MUS WITH (NOLOCK) 
		WHERE MUS.docKey = IM.docKey 
		ORDER BY MUS.UploadedWhen DESC
	) MU 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erikTsomikSystem Architect, CF programmer Author Commented:
can you explain outer apply how it works
This is the best resource that I am readily familiar with for that:

It is a handy trick.  CROSS APPLY might also work for you.  Without knowing your data/project intimately, it would be hard to say.
awking00Information Technology SpecialistCommented:
select dockey, filename, name, uploadid, uploadedwhen from
(select im.dockey, mu.filename, im.name, mu.uploadid, mu.uploadedwhen,
 row_number() over (partition by mu.dockey order by mu.uploadedwhen desc) rn
 insmanual im inner join insmanualuploads mu
 on im.dockey = mu.dockey) as x
where x.rn = 1
Vitor MontalvãoMSSQL Senior EngineerCommented:
Should be as simple as:
SELECT IM.docKey, MU.filename, IM.name, MAX(MU.UploadedWhen)
FROM InsManual IM 
INNER JOIN InsManualUploads MUS ON MUS.docKey = IM.docKey 
GROUP BY IM.docKey, MU.filename, IM.name

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.