max date and only 1 record per toolnumber

I am trying to get 1 maxdate from a table foreach toolnumber inserted but I keep getting multiple for each tool number. There should be 1 row returned for toolnumber 1, 1 for toolnumber 2, 1 for toolnumber 3 etc..........
SELECT 
a.UploadTime
      ,a.[ToolNumber]
      ,a.[ToolSize]
      ,a.[ToolStyle]
      ,a.[DefaultLocationIndex]  
      FROM ToolAssemblies a
      INNER JOIN( SELECT MAX(UploadTime) as UploadTime   ,[ToolNumb[embed=file 905894]er]
      ,[ToolSize]
      ,[ToolStyle]
      ,[DefaultLocationIndex]  FROM ToolAssemblies WHERE ToolNumber IN ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 24 , 25 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 39 , 40 , 47 , 51 , 56 , 66 , 71 , 76 , 79 , 82 ) GROUP BY ToolNumber, ToolSize,ToolStyle,DefaultLocationIndex ) b 
      ON a.UploadTime = b.UploadTime
      ORDER BY ToolNumber

Open in new window

Capture.PNG
LVL 6
r3nderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

dsackerContract ERP Admin/ConsultantCommented:
Do you even need the additional INNER JOIN on the same table?
SELECT 
       a.[ToolNumber]
      ,a.[ToolSize]
      ,a.[ToolStyle]
      ,a.[DefaultLocationIndex]
      , MAX(UploadTime) AS UploadTime
FROM ToolAssemblies a
WHERE ToolNumber IN ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 24 , 25 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 39 , 40 , 47 , 51 , 56 , 66 , 71 , 76 , 79 , 82 )
GROUP BY a.[ToolNumber]
      ,a.[ToolSize]
      ,a.[ToolStyle]
      ,a.[DefaultLocationIndex]
ORDER BY ToolNumber

Open in new window

0
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT
a.UploadTime
      ,a.[ToolNumber]
      ,a.[ToolSize]
      ,a.[ToolStyle]
      ,a.[DefaultLocationIndex]  
FROM ToolAssemblies a
WHERE ToolNumber IN ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 24 , 25 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 39 , 40 , 47 , 51 , 56 , 66 , 71 , 76 , 79 , 82 )
AND a.UploadTime = (SELECT  MAX(UploadTime) FROM ToolAssemblies a WHERE a.[ToolNumber] = b.toolNumber )
ORDER BY ToolNumber
0

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
r3nderAuthor Commented:
Perfect Thank you Aneesh
0
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
Microsoft SQL Server

From novice to tech pro — start learning today.