# A badge granted when someone posts a reply in a single specified topic

**URL:** https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [November 12, 2014, 4:46am UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673 "2014-11-12T04:46:40Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [November 12, 2014, 4:46am UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/1 "2014-11-12T04:46:40Z")

</div>

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.)

---

<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: [November 12, 2014, 6:11am UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/2 "2014-11-12T06:11:19Z")

</div>

```plaintext
SELECT
DISTINCT ON (p.user_id)
p.user_id, p.id post_id, p.created_at granted_at
FROM badge_posts p
WHERE p.topic_id = 32 AND -- 32 is the "please introduce yourself" topic
  (:backfill OR p.id IN (:post_ids) )

```

Triggered on “edit/create a post”.

---

<div class="post-metadata">

### Author: ![Frasertag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frasertag/32/69889_2.png) [@Frasertag](https://meta.discourse.org/u/Frasertag)
#### Post date: [March 27, 2017, 10:52pm UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/3 "2017-03-27T22:52:50Z")

</div>

Hi

I am seeking some help to do the following badge

I am trying to encourage users to post in a thread, I want them to post in this particular thread 10 times to earn this badge.

I was looking at

> [@riking](#):
>
> SELECT  
> DISTINCT ON (p.user\_id)  
> p.user\_id, p.id post\_id, p.created\_at granted\_at  
> FROM badge\_posts p  
> WHERE p.topic\_id = 32 AND – 32 is the “please introduce yourself” topic  
> (:backfill OR p.id IN (:post\_ids) )

Which works for a single post, I am just unsure how to expand this out to 10 posts minimum.

---

<div class="post-metadata">

### Author: ![Nigel\_Tatschner](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nigel_tatschner/32/68423_2.png) [@Nigel\_Tatschner](https://meta.discourse.org/u/Nigel_Tatschner)
#### Post date: [June 14, 2017, 3:17pm UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/4 "2017-06-14T15:17:13Z")

</div>

Can’t seem to get this to work,  
I’ve added;

> SELECT  
> DISTINCT ON (p.user\_id)  
> p.user\_id, p.id post\_id, p.created\_at granted\_at  
> FROM badge\_posts p  
> WHERE p.topic\_id = 172 AND  
> (:backfill OR p.id IN (:post\_ids) )

But running the query isn’t bringing anyone back 😢

---

<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: [June 14, 2017, 10:02pm UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/5 "2017-06-14T22:02:01Z")

</div>

Did you change the topic ID? the 172

---

<div class="post-metadata">

### Author: ![Nigel\_Tatschner](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nigel_tatschner/32/68423_2.png) [@Nigel\_Tatschner](https://meta.discourse.org/u/Nigel_Tatschner)
#### Post date: [June 15, 2017, 4:36am UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/6 "2017-06-15T04:36:59Z")

</div>

> [@riking](#):
>
> Did you change the topic ID? the 172

Yeah, I think 172 is the topic number.

---

<div class="post-metadata">

### Author: ![Timothy\_Vail](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/timothy_vail/32/90872_2.png) [@Timothy\_Vail](https://meta.discourse.org/u/Timothy_Vail)
#### Post date: [March 8, 2018, 3:15am UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/7 "2018-03-08T03:15:10Z")

</div>

> [@riking](#):
>
> SELECT  
> DISTINCT ON (p.user\_id)  
> p.user\_id, p.id post\_id, p.created\_at granted\_at  
> FROM badge\_posts p  
> WHERE p.topic\_id = 32 AND – 32 is the “please introduce yourself” topic  
> (:backfill OR p.id IN (:post\_ids) )

With the new SQL rules, how would you make a badge for introducing yourself on a topic?

---

<div class="post-metadata">

### Author: ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)
#### Post date: [June 19, 2018, 10:10pm UTC](https://meta.discourse.org/t/a-badge-granted-when-someone-posts-a-reply-in-a-single-specified-topic/276673/8 "2018-06-19T22:10:21Z")

</div>

I used this query…

```plaintext
SELECT
DISTINCT ON (p.user_id)
p.user_id, p.id post_id, p.created_at granted_at
FROM badge_posts p
WHERE p.topic_id = 6671 AND -- 6671 is the "Introduce yourself" topic
  (:backfill OR p.id IN (:post_ids) )

```

With the following settings

 ![59%20PM](https://global.discourse-cdn.com/meta/original/3X/3/9/39dcaa257a24f19815122d953fc1ddba553b0013.png)
