Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

asked on

select and count the max id

I have a query where I am trying to count the max id that meets this criteria
Select Count(ID),MAX(ID)  from  ToolAssemblies WHERE ToolNumber =52  
This should come up as 1 but it counts 29?
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of r3nder

ASKER

got the idea - thanks Jim

SELECT COUNT(ID)
FROM ToolAssemblies
WHERE id IN (Select MAX(ID)as max_id from  ToolAssemblies WHERE ToolNumber =52 )
<slight cleanup, don't need an alias with an IN clause>
SELECT COUNT(id) 
FROM ToolAssemblies
WHERE id IN (Select MAX(ID) from ToolAssemblies WHERE ToolNumber = 52 )

Open in new window

Thanks for the grade.  Good luck with your project.  -Jim