# Bulk suspend users based on criteria

**URL:** <https://meta.discourse.org/t/bulk-suspend-users-based-on-criteria/76804>\
**Category:** Product Support\
**Created:** [27.Декабрь.2017 08:06:27 UTC](https://meta.discourse.org/t/bulk-suspend-users-based-on-criteria/76804 "2017-12-27T08:06:27Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)\
**Post date:** [01.Январь.2018 19:45:52 UTC](https://meta.discourse.org/t/bulk-suspend-users-based-on-criteria/76804/13 "2018-01-01T19:45:52Z")

</div>

Thanks Blake - distinct does the trick:

```plaintext
User.joins(:group_users).where.not(group_users: {group_id: 41}).distinct.count
=> 2572

```

But something about my `.not` is off as it’s counting all users, not just the non-members of the group. The number should be 1823 instead of 2572.

```plaintext
 users = User.joins(:group_users).where(group_users: {group_id: 41}).distinct.count
=> 749

```

---

_[View the full topic](https://meta.discourse.org/t/bulk-suspend-users-based-on-criteria/76804)._
