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

Simple query?

Status
Not open for further replies.

riluve

Technical User
Mar 11, 2005
78
US
I need a query that will count the occurance of each unique entry in a specified field. E.G. given the following record set:

field1 field2
--- 'x'
--- 'y'
--- 'x'
--- 'w'

the result should be similar to:
'x' = 2
'y' = 1
'w' = 1

A critical point (if possible) is the contents of field2 should not be defined before the query. Such that the query should not need to know which patterns might be in the field. It should only worry if there is a unique pattern discoverd, the number of times the pattern occurs in the record set should be counted.

.
 
Sweet thnx - ok I got that working, but is there a way I can sort by the results of the count?

I have tried a number of different "ORDER BY" by it never seems to work.

 
select column2, count(*) as cnt
from t
group by column2
order by cnt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top