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)
 how to limit in sql2000

Author  Topic 

emailuser
Yak Posting Veteran

74 Posts

Posted - 2011-10-18 : 13:31:18
Hi everyone , i am query a database to retrieve a count of the number of calls logged and the categories they have been categorised as , the query is below , but i want to only retrieve the top 5 , i have tried TOP and LIMIT but this does not work , code is below .. any help to make this work would be really appreicated


SELECT COUNT(suppdeskdev.F0009_SUPEVENT.SSUBTYPE) AS total, suppdeskdev.SUPCATEG.CATEGORY
FROM suppdeskdev.F0009_SUPEVENT RIGHT OUTER JOIN
suppdeskdev.SUPCATEG ON suppdeskdev.F0009_SUPEVENT.SSUBTYPE = suppdeskdev.SUPCATEG.[NO]
WHERE (suppdeskdev.F0009_SUPEVENT.OPENDATE > '2011-10-01')
GROUP BY suppdeskdev.SUPCATEG.CATEGORY
ORDER BY total DESC

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-10-18 : 13:39:28
select top 5 *
from (
SELECT COUNT(suppdeskdev.F0009_SUPEVENT.SSUBTYPE) AS total, suppdeskdev.SUPCATEG.CATEGORY
FROM suppdeskdev.F0009_SUPEVENT RIGHT OUTER JOIN
suppdeskdev.SUPCATEG ON suppdeskdev.F0009_SUPEVENT.SSUBTYPE = suppdeskdev.SUPCATEG.[NO]
WHERE (suppdeskdev.F0009_SUPEVENT.OPENDATE > '2011-10-01')
GROUP BY suppdeskdev.SUPCATEG.CATEGORY
) t
order by total desc

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -