# Badge for replies in a specific category

**URL:** https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [8월 27, 2015, 2:51오후 UTC](https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730 "2015-08-27T14:51:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [8월 27, 2015, 2:51오후 UTC](https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730/1 "2015-08-27T14:51:37Z")

</div>

> [@A badge granted when someone posts a reply in a single specified topic](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/1):
>
> Anyone want a (hopefully easy) challenge? A badge granted when someone posts a reply in a single specified topic. (i.e., A “Please introduce yourself here” topic.)

I’m looking for something similar, a badge awarded when replying to posts in a particular category.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [8월 28, 2015, 12:28오전 UTC](https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730/2 "2015-08-28T00:28:40Z")

</div>

```plaintext
SELECT p.user_id user_id, min(p.id) post_id, min(p.created_at) granted_at
FROM badge_posts p
JOIN topics t ON p.topic_id = t.id
WHERE t.category_id = (SELECT id FROM categories WHERE slug = 'introductions')
GROUP BY p.user_id

```

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [8월 28, 2015, 9:54오전 UTC](https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730/3 "2015-08-28T09:54:22Z")

</div>

Crikey, if this is what I think it is, how easy is it to adapt to specify the number of posts for silver/gold badges?

```
SELECT p.user_id user_id, min(p.id) post_id, min(p.created_at) granted_at
FROM badge_posts p
JOIN topics t ON p.topic_id = t.id
WHERE t.category_id = (SELECT id FROM categories WHERE slug = 'introductions')
GROUP BY p.user_id
HAVING COUNT (*) > 10

```

Would it be that simple?

Turns out it is. Awesome, thanks @riking!

Update: throws an error on any category name which isn’t unique.

---

<div class="post-metadata">

### Author: ![PJH](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pjh/32/39071_2.png) [@PJH](https://meta.discourse.org/u/PJH)
#### Post date: [8월 28, 2015, 12:20오후 UTC](https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730/4 "2015-08-28T12:20:53Z")

</div>

> [@steve\_pd](#):
>
> Update: throws an error on any category name which isn’t unique.

Try:

> [@steve\_pd](#):
>
> WHERE t.category\_id ~~=~~ in (SELECT id FROM categories WHERE slug = ‘introductions’)

instead?

* * *

ObOT: I note that `<ins>` has been CSS’d on here, but not `<del>`…
