# Automatically Give Badge to Multiple Groups

**URL:** <https://meta.discourse.org/t/automatically-give-badge-to-multiple-groups/77812>\
**Category:** Support\
**Created:** [January 12, 2018, 6:48am UTC](https://meta.discourse.org/t/automatically-give-badge-to-multiple-groups/77812 "2018-01-12T06:48:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ForPizzaSake](https://avatars.discourse-cdn.com/v4/letter/f/cab0a1/32.png) [@ForPizzaSake](https://meta.discourse.org/u/ForPizzaSake)\
**Post date:** [January 12, 2018, 6:48am UTC](https://meta.discourse.org/t/automatically-give-badge-to-multiple-groups/77812/1 "2018-01-12T06:48:08Z")

</div>

Hey there, so I’m looking to automatically grant a badge to multiple groups. I currently have this SQL section to apply the badge to one group, but I’d like to have both `group_name_one` and `group_name_two` both get the same badge.

```sql
select user_id, created_at granted_at, NULL post_id
from group_users
where group_id = (
  select g.id from groups g where g.name = 'group_name_one'
)

```

So, how would I create two select statements together for both groups?

Thanks!

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [January 12, 2018, 10:48am UTC](https://meta.discourse.org/t/automatically-give-badge-to-multiple-groups/77812/2 "2018-01-12T10:48:31Z")

</div>

This should work:

```sql
SELECT
  gu.user_id,
  gu.created_at granted_at,
  NULL post_id
FROM group_users gu
  JOIN groups g ON (g.id = gu.group_id)
WHERE g.name IN ('group_name_one', 'group_name_two')

```

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [June 8, 2024, 12:43pm UTC](https://meta.discourse.org/t/automatically-give-badge-to-multiple-groups/77812/3 "2024-06-08T12:43:38Z")

</div>

This topic was automatically closed after 2339 days. New replies are no longer allowed.
