# Badges for posting

**URL:** https://meta.discourse.org/t/badges-for-posting/276725
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [August 19, 2014, 10:12pm UTC](https://meta.discourse.org/t/badges-for-posting/276725 "2014-08-19T22:12:41Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [August 1, 2020, 6:06am UTC](https://meta.discourse.org/t/badges-for-posting/276725/4 "2020-08-01T06:06:35Z")

</div>

> [@PJH](#):
>
> ```plaintext
> SELECT user_id, 0 post_id, current_timestamp granted_at 
> FROM badge_posts  
> WHERE (:backfill OR user_id IN (:user_ids) OR 0 NOT IN (:post_ids) )
> GROUP BY user_id 
> HAVING count(*) > 1000
> 
> ```

I just found this little gem here. I wanted to create my own custom badge queries for number of posts in specific categories. How can one modify this to also include the condition of specific category ids so only posts in a specific category will count?

> [@Some common badge queries](https://meta.discourse.org/t/some-common-badge-queries-idea/31859):
>
> warning Enabling Badge SQL entails security and performance risks so it is not available by default. For more information, see: [Enable Badge SQL](https://meta.discourse.org/t/badge-sql-can-no-longer-be-edited-by-default/47894) Here are some common badge queries which you can use to create your own awesome badge! Grant a badge if user has created at least one topic in the “foo”\* category \*(“foo” is the category name, not the category slug) SELECT p.user\_id, min(p.created\_at) granted\_at, MIN(p.id) post\_id FROM badge\_posts p JOIN topics t ON t.id = p.topic\_id WHERE cate…

Should be a modification of the first query here where badges are awarded based on creating topics in a specific category. The difference is we award based on number of posts in a specific category.

---

_[View the full topic](https://meta.discourse.org/t/badges-for-posting/276725)._
