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
 Transact-SQL (2000)
 How To Order By Count Field

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-15 : 07:43:05
Eric Moore writes "I have this query:

select mycolumn, count(mycolumn) as mycolcount
from mytable

I want to be able to order by the count, however, this is an aggregate field?

How do I do this?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-08-15 : 07:43:33
Yes, you can do that:

select mycolumn, count(mycolumn) as mycolcount
from mytable
order by count(mycolumn)
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2005-08-15 : 11:11:49
or
select mycolumn, count(mycolumn) as mycolcount
from mytable
order by 2
Go to Top of Page
   

- Advertisement -