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 2008 Forums
 Transact-SQL (2008)
 SQL QUERY

Author  Topic 

spoutnick
Starting Member

6 Posts

Posted - 2011-08-16 : 06:38:09
HELLO ALL,
i have a table like this
COL1 COL2
AAA MAR
AAA MAR
AAA OUJ
BBB OUJ
BBB MAR
BBB BNI
i would like to use sql query to get
AAA 2
BBB 3
THANKS IN ADVANCE

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-08-16 : 07:10:18
Here is a way to do this:

select col1,count(*)
from
(
select distinct col1,col2
from YourTable
) s
group by col1;
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-16 : 07:13:07
[code]
select COL1, count(distinct COL2)
from YourTable
group by COL1
[/code]


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

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-08-16 : 07:18:20
Hah! That is what I missed!! I knew there was a better way to do it!! thanks KH.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-16 : 07:19:15
quote:
Originally posted by sunitabeck

Hah! That is what I missed!!



Coffee ?


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

Go to Top of Page

spoutnick
Starting Member

6 Posts

Posted - 2011-08-16 : 07:22:33
THANKS IT WORKS
Go to Top of Page
   

- Advertisement -