# Assigned a badge based on multiple badge assignment

**URL:** https://meta.discourse.org/t/assigned-a-badge-based-on-multiple-badge-assignment/221251
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [March 17, 2022, 4:31pm UTC](https://meta.discourse.org/t/assigned-a-badge-based-on-multiple-badge-assignment/221251 "2022-03-17T16:31:49Z")
**Posts on this page:** 1
**Showing post:** 7

<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: [March 18, 2022, 4:41pm UTC](https://meta.discourse.org/t/assigned-a-badge-based-on-multiple-badge-assignment/221251/7 "2022-03-18T16:41:56Z")

</div>

It looks like you ran that in the [data explorer](https://meta.discourse.org/t/32566?silent=true). For the custom SQL badges you would need to turn on the hidden site setting and add the query to the badge page:

> [@Creating triggered custom badge queries](https://meta.discourse.org/t/triggered-custom-badge-queries/19336):
>
> bookmark This guide explains how to create triggered custom badge queries in Discourse, including the types of badges, constraints for triggered badges, and an example query. person_raising_hand Required user level: Administrator warning This feature is disabled by default. To enable it, follow [this guide](https://meta.discourse.org/t/badge-sql-can-no-longer-be-edited-by-default/47894). When defining badges in Discourse, you’ll encounter a “Trigger” option with the following choices: Update daily When a user acts on post When a user edits or creates a post When…

However, not everyone can do that depending on their hosting package.

But a [data explorer](https://meta.discourse.org/t/32566?silent=true) one is more than possible too if you can’t have the custom SQL triggered ones. 👍 I think you’d have to make some choices about how often you ran it, and how the Badges would be awarded from the results (manually one by one, or through the bulk award), but it’s definitely do-able.

Something simple may be better, though you perhaps want to add a date range parameter too?

```plaintext
WITH foo AS (SELECT ub.user_id,count(ub.user_id), max(ub.granted_at) granted_at
FROM user_badges ub
WHERE ub.badge_id=108
GROUP BY ub.user_id) 

SELECT user_id, granted_at
FROM foo
WHERE count >4
ORDER BY granted_at DESC

```

---

_[View the full topic](https://meta.discourse.org/t/assigned-a-badge-based-on-multiple-badge-assignment/221251)._
