Need help on MySQL DISTINCT+COUNT query

lambal

New Member
I have a table called "r", inside that table I store id, ip, and country. I am running this query:\[code\]SELECT r.country, count(rr.ip), count(DISTINCT rr.ip) FROM `r` LEFT JOIN r rr ON r.country = rr.country GROUP BY r.country\[/code\]I do get rows with columns: "country";"number";"number";But both "counts()" doesn not show what I want it to show (count of raw/unique ips for each country), and I am not sure why. For example for US I see >2000 unique ips, but I only have 500 entries in the database. What is wrong with my query?What I want to retrieve from the db is a list of row with columns: countries + count raw ips + count unique ips. (count related to each country), I mean retrieve a list of distinct countries and counting ips foreach one (without having to do multiple queries).
 
Back
Top