# Identify private message interactions between users

**URL:** https://meta.discourse.org/t/identify-private-message-interactions-between-users/167067
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [October 13, 2020, 9:31am UTC](https://meta.discourse.org/t/identify-private-message-interactions-between-users/167067 "2020-10-13T09:31:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sonicb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sonicb/32/186395_2.png) [@sonicb](https://meta.discourse.org/u/sonicb)
#### Post date: [October 13, 2020, 9:31am UTC](https://meta.discourse.org/t/identify-private-message-interactions-between-users/167067/1 "2020-10-13T09:31:41Z")

</div>

I’d like to use the [Data Explorer plugin](https://meta.discourse.org/t/data-explorer-plugin/32566) to identify whether users are interacting with each other. I wrote a query to return the sender, recipient and a count for a provided date range, however it seems to be returning responses for topics. Any idea what I might be doing wrong?

```
-- [params]
-- int :interval_days = 14

SELECT topics.user_id, n.user_id, count(*) as message_count
FROM topics
JOIN notifications n ON n.topic_id = topics.id
JOIN users u ON u.id = topics.user_id
WHERE archetype = 'private_message' AND subtype = 'user_to_user'
AND age(n.created_at) < interval ':interval_days days'
AND u.name != 'system'
GROUP BY topics.user_id, n.user_id
ORDER by message_count DESC

```

---

<div class="post-metadata">

### Author: ![sonicb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sonicb/32/186395_2.png) [@sonicb](https://meta.discourse.org/u/sonicb)
#### Post date: [October 13, 2020, 4:47pm UTC](https://meta.discourse.org/t/identify-private-message-interactions-between-users/167067/2 "2020-10-13T16:47:04Z")

</div>

I added a `notification_type` of 6 (private\_message) to get this to work:

`AND n.notification_type = 6`

---

<div class="post-metadata">

### Author: ![osioke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osioke/32/238946_2.png) [@osioke](https://meta.discourse.org/u/osioke)
#### Post date: [October 13, 2020, 8:55pm UTC](https://meta.discourse.org/t/identify-private-message-interactions-between-users/167067/3 "2020-10-13T20:55:06Z")

</div>


