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

Most entries into ordered list 1

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
I have studied the distinct and count questions, but could not find the solution.

I have a table MYTABLE with entries for the field NAMES.
I now wish to draw up a list of the 5 most used names and put that list into a combobox ordered from most entries to least entries such as in :

Select distinct top 5 NAMES, count(NAMES) as TimesEntered from MYTABLE order by TimesEntered.

Help will be appreciated.

Thanks
 
SELECT TOP 5 NAMES, Count(*) AS TimesEntered FROM MYTABLE ORDER BY 2 DESC

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, sorry:
SELECT TOP 5 NAMES, Count(*) AS TimesEntered FROM MYTABLE GROUP BY NAMES ORDER BY 2 DESC

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top