I want the total unique occurences of NAME
from the MS SQL database, but only once for every user. Below is a sample of my data.
USERID NAME
------------------------
1 name 1
1 name 1
1 name 1
2 name 1
2 name 2
2 name 3
3 name 1
3 name 1
3 name 3
4 name 1
If I use the following query
SELECT COUNT(name) AS total, name FROM TestTable GROUP BY name
I get the following results
7 name 1
1 name 2
2 name 3
But what I want is the result below. The query should ignore 2x name 1
from user 1 and 1x name 1
from user 3.
4 name 1
1 name 2
2 name 3
I have insufficient knowledge of SQL to get this to work, or to know the correct terms to use in the query. So there probably is a duplicate and if so, please point me to it.