1

I have a table such as the following

id_profile, id_user
1         , 5
1         , 4
1         , 4
1         , 4
2         , 1
2         , 5
2         , 2

I'm trying to count id_user but I have to eliminate duplicates. So, I want a result like

id_profile, count
1         , 2
2         , 3

Any suggestions?

2 Answers 2

3

Do a GROUP BY, use count distinct:

select id_profile, count(distinct id_user) as count
from tablename
group by id_profile
Sign up to request clarification or add additional context in comments.

1 Comment

THANK YOU VERY VERY MUCH
1

You can use a sub-query to filter distinct values and then use count, group by on that if that's easier to understand.

SELECT id_profile, COUNT(id_user)
    FROM(SELECT DISTINCT id_profile,id_user FROM tablename)
    GROUP BY id_profile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.