I need a little help here with a query. I want to count from a result set duplicate ip’s and put that together with a username.
the origional result set is
Name | IP
--------------
Bert | 192.168.1.1
Bert | 192.168.1.5
Laura| 192.168.1.2
and I want this:
Name | IpCount
--------------
Bert | 2
Laura| 1
My query so far is:
select ips.userName, COUNT(ips.userIP) as cnt
from (select u.userName, u.userIP from
users) as ips
group by ips.userName, ips.userIP
But that gives me the wrong counts, can somebody help me?
EDIT:
I used the word duplicate, but it should be: different. Sorry folks.
Assuming your example has a typo and you mean
and your table is named Users. This query should do
Update
as pointed out by @Andriy M this query should do