Forum Moderators: open
I can't get this bloody thing to work..
This is the database I have:
id ¦ token ¦ value
------------------
1 ¦ 11111 ¦ aaaaa
2 ¦ 11111 ¦ aaaaa
3 ¦ 11111 ¦ aaaaa
4 ¦ 11111 ¦ bbbbb
5 ¦ 11111 ¦ bbbbb
6 ¦ 22222 ¦ ccccc
7 ¦ 22222 ¦ ccccc
My goal is to count the unique values with each token. Like in the example above, there are 3 "aaaaa" values, but I want MySQl to count them as one. The output I'm looking is:
token: 11111, values: 2
token: 22222, values: 1
What I managed to do is just count all the values and group them with the tokens:
SELECT token, count(value) as result FROM database GROUP BY token
But the problem is that this way MySQL counts all of the values, but I just want unique values.