SQL – Counting Users That Have Multiple Inputs In Another Column

Use group by and having. If you want the list of users that have more than one account, then:

select user
from mytable
group by user
having count(*) > 1

This assumes no duplicates (user, account). Else, you need to change the having clause to:

having count(distinct account) > 1

Or:

having min(account) <> max(account)

Now, if you want the count of such users, just add another level of aggregation:

select count(*) cnt
from (
    select user
    from mytable
    group by user
    having count(*) > 1
) t

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top