Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



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

Posts: 186
Location: London UK
Trades: 0
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
 
 
Register now for full access!
Old 02-29-2008, 06:49 PM Re: count() group by and null values
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to count() group by and null values
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.33283 seconds with 12 queries