# Created a topic in a specific category with conditions

**URL:** https://meta.discourse.org/t/created-a-topic-in-a-specific-category-with-conditions/281550
**Category:** Data & reporting
**Tags:** sql-triggered-badge
**Created:** [December 26, 2022, 12:38pm UTC](https://meta.discourse.org/t/created-a-topic-in-a-specific-category-with-conditions/281550 "2022-12-26T12:38:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [December 26, 2022, 12:38pm UTC](https://meta.discourse.org/t/created-a-topic-in-a-specific-category-with-conditions/281550/1 "2022-12-26T12:38:04Z")

</div>

I tried this for users who have created a new Topic in a specific Category that satisfied some conditions.

```sql
SELECT DISTINCT ON (p.user_id) p.user_id, p.id post_id, p.created_at granted_at
FROM posts p
INNER JOIN topics t
ON p.topic_id=t.id
WHERE t.category_id = 99 AND p.post_number=1 AND <conditions here> AND
  (:backfill OR p.id IN (:post_ids) )

```
