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 
            Asked
            
        
        
            Active
            
        
            Viewed 610 times
        
    -1
            
            
         
    
    
        forpas
        
- 160,666
- 10
- 38
- 76
 
    
    
        Giriteja Bille
        
- 168
- 1
- 13
- 
                    https://stackoverflow.com/help/minimal-reproducible-example – Shoaeb May 09 '20 at 09:58
2 Answers
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
- 
                    **Thanks for the clear explanation!**.I had it working properly – Giriteja Bille May 09 '20 at 10:14