Reply
count() group by and null values
Old 02-29-2008, 01:35 PM count() group by and null values
hiptobesquare's Avatar
Extreme Talker

Posts: 159
Location: London UK
Hi

Im trying to make a query which counts the number of venues in each county of the uk from 2 tables of my database. The trouble im having is in making counties with 0 venues show up in the results, it seems that the group function removes all trace of counties which have no venues.

it goes like this -

select p.county, count(u.venueid) from postcodes p
left join venue u on SUBSTRING_INDEX(u.postcode, ' ', 1)=p.postcode
where u.status='active'
group by p.county order by p.county


It must be a common issue but i can only find 1 other post about it and it has no replies.

anybody have any ideas?
hiptobesquare is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 02-29-2008, 05:49 PM Re: count() group by and null values
Learning Newbie's Avatar
Moderator

Posts: 4,585
Name: John Alexander
P is the outer table in your join, so p.country does not exist. To get a value out of it, you'll need to coalesce or isnull it.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to count() group by and null values
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11404 seconds with 13 queries