# Return all non-PM topics that have not received a staff reply

**URL:** https://meta.discourse.org/t/return-all-non-pm-topics-that-have-not-received-a-staff-reply/275165
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [August 17, 2019, 12:14am UTC](https://meta.discourse.org/t/return-all-non-pm-topics-that-have-not-received-a-staff-reply/275165 "2019-08-17T00:14:29Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [August 17, 2019, 12:14am UTC](https://meta.discourse.org/t/return-all-non-pm-topics-that-have-not-received-a-staff-reply/275165/1 "2019-08-17T00:14:29Z")

</div>

Here’s one that should return all non-PM topics that have not received a staff reply:

```sql
SELECT t.id topic_id, category_id
FROM topics t
WHERE t.deleted_at IS NULL
  AND t.category_id IS NOT NULL
  AND t.id NOT IN (
    SELECT p.topic_id
    FROM posts p 
    JOIN users u ON p.user_id = u.id
    WHERE u.admin = 't' OR u.moderator = 't'
      AND p.post_number > 1
  )

```

---

_[View the full topic](https://meta.discourse.org/t/return-all-non-pm-topics-that-have-not-received-a-staff-reply/275165)._
