I tried looking around for similar solutions but it didn't seem to help much in my case. I have a table as such:
locations => |longname|name|locations|
topics => |longname|name|tag|
and I am trying to get the count of longnames with a specific atag
for a particular location. The query I have so far also tries to force reordering, which is why you see the location IN
and FIELD
. However, if there aren't any people in a location for a particular tag, it omits it entirely from the response. I'd like it to return 0. How can I do that?
select count(b.longname) as count, a.location
from `topics` b, locations a
where tag = 'atag' and a.longname = b.longname
and location IN ('Japan', 'France', 'Italy')
group by location
order by FIELD(location, 'Japan', 'France', 'Italy')