Automatically Give Badge to Multiple Groups

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.

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!

This should work:

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')
7 Likes

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