I may be a bit rusty on my SQL syntax, so it’s nearly impossible for me to figure this out on my own. I have a typical MySQL installation with the following table, “history”.
userid ip
----------- ----------
1 123.123.123.123
1 123.123.123.123
1 111.111.111.111
2 213.213.213.213
2 214.214.214.214
2 215.215.215.215
3 163.123.121.123
4 111.222.121.212
Essentially, I am logging certain things under a certain user ID and what IP address they currently use (along with other things, but that’s not needed). However, my final task I want to achieve is to create a listing for every user with how many IPs have been used. The final result in this case would be.
userid ipcount
----------- ----------
1 2
2 3
3 1
4 1
I know this would be possible somehow, but I am quite the novice at SQL (I was able to get the count, but not to group it down by the userid). I could do this in PHP in a snatch, but that’s extra overload for the server (I have about 5K entries at the moment). SQL was made exactly to do this…
Thanks guys. 🙂
1 Answer