Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
select count(distinct <colname>) from <table_name>

select distinct count(<colname>) from <table_name>


What is the difference between these two ?


plz explain
Posted

1) when u write this way..
SQL
select   count(distinct ACODE) from dbo.Table_1

then it counts for different values like my table(dbo.table_1) having ACODE column which has certain values
VB
ACODE
2010
2010
2009
2011
2011
2009
2010
2011


now if i execute first query will get ans = 3, bcoz it counts only distinct values.

2)now,
SQL
select  distinct count(ACODE) from dbo.Table_1
if u execute this then u will get answer = 8

bcoz, it has 3 times -2010, 3 times - 2011 , and 2 times - 2009

this count for all the records and give output, and does not give count for distinct value.

3)if u want to analyse it more deeply then try it by exicuting this query..

select   distinct count(ACODE),ACODE from dbo.Table_1 group by ACODE



hope this help..
 
Share this answer
 
v2
Comments
Ajit Kumar Nayak 17-Oct-11 9:02am    
Thanks a lot
[no name] 17-Oct-11 10:35am    
yah, it sounds good
Read the following :
COUNT (Transact-SQL)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900