# Using Reactions to grant badges

**URL:** <https://meta.discourse.org/t/using-reactions-to-grant-badges/284040>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [October 30, 2023, 10:52am UTC](https://meta.discourse.org/t/using-reactions-to-grant-badges/284040 "2023-10-30T10:52:17Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [October 31, 2023, 3:06pm UTC](https://meta.discourse.org/t/using-reactions-to-grant-badges/284040/4 "2023-10-31T15:06:43Z")

</div>

I have one that I was playing with, though I put it to one side to look at it with fresh eyes and haven’t got back to it yet, so it may need some work. It’s to award a badge based on getting at least 10 posts with the :chefs_kiss: reaction given by a member of the ‘data-team’ group for posts in the #data-reporting category:

```sql
SELECT p.user_id, MIN(p.created_at) granted_at
FROM badge_posts p
  JOIN topic_tags tt ON tt.topic_id = p.topic_id
WHERE tt.tag_id = 615
  AND EXISTS (
         SELECT 1
            FROM discourse_reactions_reactions dr 
             JOIN discourse_reactions_reaction_users dru ON dr.id = dru.reaction_id
             JOIN group_users gu ON gu.user_id = dru.user_id
            WHERE dr.post_id = p.id
              AND dr.reaction_value = 'chefs_kiss'
              AND gu.group_id = 175
       )
 GROUP BY p.user_id
HAVING COUNT(*) >= 10

```

Though I wasn’t pleased with using the `MIN` as it gave the wrong awarded date.

There’s a lot of criteria to it, and it’s automatic, which I think pushes it to the more complicated end. I think a simpler one could be much more achievable without too much effort.

---

_[View the full topic](https://meta.discourse.org/t/using-reactions-to-grant-badges/284040)._
