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 count unique records

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-04-12 : 22:49:51
Hi friends
how to write a sql statement tht return count unique records
i mean if have value like below

10
10
12
12
1

my sql stmt should return 3 (i.e. two 10s + two 12s + one 1)
Thanks for the help.

Cheers

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-12 : 22:52:32
[code]select count(distinct yourcolname) from yourtable[/code]



KH


Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-04-12 : 22:56:21
oops .Thanks KH .tht worked nicely.
actually i've benn trying
select count(distinct yourcolname) from yourtable group by yourcolname
damn!!

Cheers
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-13 : 05:14:12
If you use Group by then Distinct is not required and vice versa

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2006-04-17 : 17:00:57
Thanks Madhivanan.understood

Cheers
Go to Top of Page
   

- Advertisement -