<p>If you're looking for a SQL query (as opposed to an element query), then you can use this:</p>
<pre><code>SELECT userId FROM craft_usergroups_users GROUP BY userId HAVING COUNT(*) &gt; 1;
</code></pre>
<p>This only gets the userId.</p>

CC BY-SA 4.0
2020-09-01T09:38:00.737Z
Cool. Thanks :)
Jonathan Schofield
CC BY-SA 4.0
2020-09-01T02:25:55.127Z
2020-09-01T02:25:55.127Z
CraftQuest
<p>I'm working with a site that has a few thousand user accounts. With the exception of core accounts with CP access, each user account exists for the purpose of access to event URLs which eventually expire.</p>
<p>But, although the vast majority of users belong to only one event-specific user group, a select few belong to more than one.</p>
<p>For the purposes of housekeeping, I'd like to be able to easily find such user accounts, so I can exclude them from a periodic account deletion process.</p>
<p>What query could serve this purpose for a report of multi-user-group users?</p>

<users><user-groups>
Query to find users who are in more than one user group
# Query to find users who are in more than one user group

(Asked by: username_0 on 2020-09-01)

I'm working with a site that has a few thousand user accounts. With the exception of core accounts with CP access, each user account exists for the purpose of access to event URLs which eventually expire.

But, although the vast majority of users belong to only one event-specific user group, a select few belong to more than one.

For the purposes of housekeeping, I'd like to be able to easily find such user accounts, so I can exclude them from a periodic account deletion process.

What query could serve this purpose for a report of multi-user-group users?

**Tags:** users, user-groups

---

## 1 answers

### Answer by username_1 on 2020-09-01. Score: 2

If you're looking for a SQL query (as opposed to an element query), then you can use this:
SELECT userId FROM craft_usergroups_users GROUP BY userId HAVING COUNT(*) > 1;

This only gets the userId.

> **Comments:**
> **username_0**: Cool. Thanks :)  

---

