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 2005 Forums
 Transact-SQL (2005)
 find the most repeated nos. in a column

Author  Topic 

kieran5405
Yak Posting Veteran

96 Posts

Posted - 2009-04-03 : 12:00:24
Hi,

I thought this would be simple but now it looks like i am in fact the simple one!!!

I have a table which has one column for employee nos. The employee nos can be repeated in this column.

I am trying to find the largest number of repeats for a number in the column. For example, employee no 5 is repeated 50 times...and so is repeated the most.

But I can not figure a way to do this.

Thanks for any input...

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-03 : 12:07:00
[code]select
top 1 empid,count(empid)
from
yourtable
group by
empid
order by
2 desc[/code]
Go to Top of Page

kieran5405
Yak Posting Veteran

96 Posts

Posted - 2009-04-03 : 12:12:11
cheers...worked perfectly.

why cant i work this stuff out!!!

Go to Top of Page
   

- Advertisement -