Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have simple query in which count of distinct chemist id is retrieved for particular user.


if i write -> count(distinct(chemist_id)) -> it returns= 1 [here chemist_id=0]
if i write -> count(chemist_id) -> it returns= 9 (9 times user add other chemist details(not registered chemist details))

how distinct count=1 if id's are 0

Please tell me how it is possible?
Posted
Comments
choudhary.sumit 11-Dec-12 0:06am    
post your full query with some table records fro example.
Sweetynewb 11-Dec-12 0:33am    
Query:

select count(distinct(cb.chemist_name)) as SumChem
from educator_call_dtls ed
left join chem_business_data cb on cb.call_id=ed.call_id
where ed.eid=780 and month(ed.call_date)=11 and year(ed.call_date)=2012

Table:chem_business_data has 9 records:

ID chem_id call_id patient_count other_chemist_name location
46367 0 64866 0 MEDICAL SHOP DEVICE DEMO SALEM
46368 0 64869 0 MEDICAL SHOP DEVICE DEMO SALEM
48741 0 67806 0 MEDICAL SHOP DEVICE DEMO SALEM
48750 0 67812 0 MEDICAL SHOP DEVICE DEMO SALEM
48749 0 67810 0 CANOPY ERODE
49790 0 69546 0 MEDICAL SHOP DEVICE DEMO SALEM
51811 0 71874 0 MEDICAL SHOP DEVICE DEMO SALEM
51867 0 71912 0 MEDICAL SHOP DEVICE DEMO SALEM
51808 0 71869 0 MEDICAL SHOP DEVICE DEMO SALEM

Hi,

Count(chemist_id) - returns count of rows in the table

count(distinct chemist_id) - returns count of distinct (or unique) chemist_id. Which means all rows in the table have same chemist_id.
 
Share this answer
 
v4
-- For Better Understanding--

Chem_id (0,0,0,0,1,1,1,4,4,4,4,4)
Count(Chem_id)=12
Count(Distinct(Chem_id))=3 ( Here 0,1,4)
 
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