looking for some solutions? You are welcome.

SOLVED: return 0 if no value is found for any value in WHERE IN clause

user2288650:

I have following query that returns count of unique age of users

SELECT name,COUNT(age) FROM visitor_interview WHERE age IN (27,26,23) group by age

This query returns following (unique age and their count)

array(2) { ["age"]=> int(26) ["count(age)"]=> int(3) } 
array(2) { ["age"]=> int(27) ["count(age)"]=> int(2) } 

I do not have any user with age 23 therefore, it does not return any value for that

Is there a way I can get count=0 for age 23. Like following

array(2) { ["age"]=> int(26) ["count(age)"]=> int(3) } 
array(2) { ["age"]=> int(27) ["count(age)"]=> int(2) }
array(2) { ["age"]=> int(23) ["count(age)"]=> int(0) }



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent