# List all open PMs

**URL:** https://meta.discourse.org/t/list-all-open-pms/275045
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [March 15, 2019, 12:57pm UTC](https://meta.discourse.org/t/list-all-open-pms/275045 "2019-03-15T12:57:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rishabh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rishabh/32/179446_2.png) [@rishabh](https://meta.discourse.org/u/rishabh)
#### Post date: [March 15, 2019, 12:57pm UTC](https://meta.discourse.org/t/list-all-open-pms/275045/1 "2019-03-15T12:57:56Z")

</div>

### List all open PMs

_sorted by recent activity_

```sql
SELECT
  t.id AS topic_id, 
  t.user_id 
FROM
  topics t 
  JOIN posts p ON t.id = p.topic_id 
WHERE
  t.archetype = 'private_message' 
  AND t.user_id > 0 
  AND t.reply_count > 1 
  AND NOT t.closed 
GROUP BY
  t.id 
ORDER BY
  t.updated_at DESC

```
