sql - Mysql Query [0001] -
i have 2 mysql , i'm trying number of owners own @ least 1 dog, each city. tables are:
owners id, name, city
and
dogs id, owner_id, name, weight
i have following far:
select owners.city, count(dogs.id) 'owners' owners inner join dogs on (owners.id = dogs.owner_id) group owners.city
however, gives me total number of dogs per city. i'd number of dog owners per city.
how should this?
you have count owners id distinct word, counts unique owners.
select owners.city, count(distinct owners.id) 'owners' owners inner join dogs on (owners.id = dogs.owner_id) group owners.city
Comments
Post a Comment