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
 select field and the count from the same field

Author  Topic 

awhacked
Starting Member

2 Posts

Posted - 2010-04-19 : 22:29:46
Hi all,

I have a table like bellow:

Table1

Code Field1
1 aaa
2 bbb
3 ccc
1 ddd
1 eee
2 fff
1 ggg

What i want is to get the code and the count of each code and the result should be like this:

Code Count(code)
1 4
2 2
3 1

Is it possible? Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-19 : 22:40:24
[code]
select Code, count(code)
from Table1
group by Code
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

awhacked
Starting Member

2 Posts

Posted - 2010-04-19 : 22:53:59
that's what i want.. it's easy but i missed the group.. thanks very much KH :)
Go to Top of Page
   

- Advertisement -