# Need help with an SQL badge query

**URL:** <https://meta.discourse.org/t/need-help-with-an-sql-badge-query/72021>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [October 13, 2017, 4:08pm UTC](https://meta.discourse.org/t/need-help-with-an-sql-badge-query/72021 "2017-10-13T16:08:39Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [November 29, 2019, 9:43pm UTC](https://meta.discourse.org/t/need-help-with-an-sql-badge-query/72021/6 "2019-11-29T21:43:47Z")

</div>

> [@Bernstein](#):
>
> I finally realized why this code wasn’t working. I can’t award badges to categories that are limited to certain trust levels.

You can do this. The problem is that the query is using the `badge_posts` table. The `badge_posts` table doesn’t include posts from protected categories. If the query is changed to use the `posts` table instead of the `badge_posts` table, it should work.

---

_[View the full topic](https://meta.discourse.org/t/need-help-with-an-sql-badge-query/72021)._
