# Replied to topics in a certain category, but exclude replies to own topics

**URL:** https://meta.discourse.org/t/replied-to-topics-in-a-certain-category-but-exclude-replies-to-own-topics/276724
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [2015 年 10 月 24 日午後 4:09 UTC](https://meta.discourse.org/t/replied-to-topics-in-a-certain-category-but-exclude-replies-to-own-topics/276724 "2015-10-24T16:09:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nstemp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nstemp/32/116950_2.png) [@nstemp](https://meta.discourse.org/u/nstemp)
#### Post date: [2015 年 10 月 24 日午後 4:09 UTC](https://meta.discourse.org/t/replied-to-topics-in-a-certain-category-but-exclude-replies-to-own-topics/276724/1 "2015-10-24T16:09:18Z")

</div>

Hello!

I want to create a badge for those who help in the forums, so I want to give it to the people who have replied X times to ANY thread inside the category ‘Help’. Of course this has to avoid replies in your own topic.

Please any help would be great! I have no idea how to deal with this kind of databases (I’m new to discourse 😄)

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [2015 年 10 月 28 日午前 12:04 UTC](https://meta.discourse.org/t/replied-to-topics-in-a-certain-category-but-exclude-replies-to-own-topics/276724/2 "2015-10-28T00:04:07Z")

</div>

I need something similar. For now I use this code, trigger daily:

> [@Badge for replies in a specific category](https://meta.discourse.org/t/badge-for-replies-in-a-specific-category/276730/2):
>
> 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

And this is the problem:

> [@nstemp](#):
>
> Of course this has to avoid replies in your own topic.

Users that start topics inside particular category **must be excluded** from count.  
We have a little number of users that write a lot of posts in a single topic only to reply a single question ☹

---

<div class="post-metadata">

### Author: ![alefattorini](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alefattorini/32/119928_2.png) [@alefattorini](https://meta.discourse.org/u/alefattorini)
#### Post date: [2015 年 10 月 28 日午前 11:36 UTC](https://meta.discourse.org/t/replied-to-topics-in-a-certain-category-but-exclude-replies-to-own-topics/276724/3 "2015-10-28T11:36:56Z")

</div>

I’m interested into it as well, how to avoid such problem?
