-1

i have a table named city in my database and I have tried using theselect distinct count(*) from city but it's not returning the answer that is required

forpas
  • 160,666
  • 10
  • 38
  • 76
Giriteja Bille
  • 168
  • 1
  • 13

2 Answers2

1

You should apply DISTINCT inside COUNT() for the column that you want the result:

select count(distinct columnname) 
from city
forpas
  • 160,666
  • 10
  • 38
  • 76
1

Let's dissect the problem you are facing so that you can learn too rather than just copying out the solution.

You have to find out the distinct entries from a particular column in a table. You would use the DISTINCT clause. Refer

MySQL DISTINCT clause is used to remove duplicate records from the table and fetch only the unique records. The DISTINCT clause is only used with the SELECT statement.

Syntax:

SELECT DISTINCT expressions  
FROM tables  
[WHERE conditions]; 

Now you want to count the distinct entries from a column so you can just use the count clause with distinct clause enclosed in it.

For example -

select count(distinct columnname) 
from tablename
Rush W.
  • 1,321
  • 2
  • 11
  • 19