Link to home
Start Free TrialLog in
Avatar of JCWEBHOST
JCWEBHOST

asked on

sql DISTINCT

hey guy i need to count the number of DISTINCT

but this statement

SELECT DISTINCT description, COUNT(DISTINCT description) from groupon GROUP BY description

output

description                                                                              Column1    
  d                                                                                                  1

i have d description in my table
Avatar of Xaelian
Xaelian
Flag of Belgium image

Can you do this:

SELECT count(DISTINCT description) FROM groupon GROUP BY description;
SELECT description, COUNT(DISTINCT description) from groupon GROUP BY description
SELECT COUNT(description) , description FROM GROUPON GROUP BY description
Avatar of Qlemo
Besides the first DISTINCT is superfluous (group-by columns are always distinct) I cannot see something wrong. Try
select distinct description from groupon;
select description, count(*), count(description), count(distinct description) from groupon group by description;

Open in new window

to compare the results.
You dont need to use distinct, you are already grouping with the field
If you simply need to display the distinct descriptions

select description
from groupon
group by description

or if you want to use distinct

select distinct description
from groupon
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial