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
 General SQL Server Forums
 New to SQL Server Programming
 count

Author  Topic 

pureclass85
Starting Member

29 Posts

Posted - 2009-03-11 : 13:52:41
how do i count and display the highest number of duplicated data ie


col
a
a
a
a
b
b
b
c
c

then display a table like:
entry | number of entries
a | 4

nr
SQLTeam MVY

12543 Posts

Posted - 2009-03-11 : 14:06:52
select col, num = count(*)
from tbl
group by col
order by count(*) desc

for the top one
select top 1 col, num = count(*)
from tbl
group by col
order by count(*) desc


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pureclass85
Starting Member

29 Posts

Posted - 2009-03-11 : 14:17:37
very odd dosnt seam to work
Go to Top of Page

pureclass85
Starting Member

29 Posts

Posted - 2009-03-11 : 14:33:35
it works but i dont know how to only get the highest value and none of the rest 'top 1' dosent seam to work
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-11 : 15:03:32
The top 1 query should work fine...whats the error you get when you run it?
Go to Top of Page

pureclass85
Starting Member

29 Posts

Posted - 2009-03-11 : 15:12:22
'You have an error in your sql syntax' error 1064
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-11 : 15:13:29
Can you post the exact query you tried?
Go to Top of Page

pureclass85
Starting Member

29 Posts

Posted - 2009-03-11 : 15:16:24
just fixed it!! thanks
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-11 : 15:34:02
Ok...great
Go to Top of Page
   

- Advertisement -