# Invite badges from inviting yourself

**URL:** <https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143>\
**Category:** UX\
**Tags:** invites\
**Created:** [February 14, 2022, 5:04pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143 "2022-02-14T17:04:14Z")\
**Posts on this page:** 1\
**Showing post:** 22

<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:** [January 5, 2023, 4:13pm UTC](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143/22 "2023-01-05T16:13:12Z")

</div>

> [@tobiaseigen](#):
>
> Is there any way we could sidestep this problem by changing how the badge is awarded? E.g. if the person redeeming the invite is already a member, do not award the campaigner badge to the person who created the invitation?

My SQL probably needs checking 🙂, but I believe you could add this line to the badge query to stop it being granted to people who have invited themselves - `AND i.invited_by_id <> u2.id`

So something like this:

```plaintext
SELECT u.id user_id, current_timestamp granted_at 
FROM users u 
WHERE u.id IN (
  SELECT invited_by_id 
  FROM invites i 
  JOIN invited_users iu ON iu.invite_id = i.id 
  JOIN users u2 ON u2.id = iu.user_id 
  WHERE i.deleted_at IS NULL
  AND i.invited_by_id <> u2.id
  AND u2.active 
  AND u2.trust_level >= 0 
  AND u2.silenced_till IS NULL 
  GROUP BY invited_by_id 
  HAVING COUNT(*) >= 1 
) AND u.active AND u.silenced_till IS NULL AND u.id > 0 AND
(:backfill OR u.id IN (:user_ids) ) 	

```

---

_[View the full topic](https://meta.discourse.org/t/invite-badges-from-inviting-yourself/218143)._
