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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -