# Topics where user mentioned and hasn’t responded after being mentioned

**URL:** https://meta.discourse.org/t/topics-where-user-mentioned-and-hasn-t-responded-after-being-mentioned/275152
**Category:** Data & reporting
**Tags:** sql-query, mentions
**Created:** [March 16, 2019, 12:00am UTC](https://meta.discourse.org/t/topics-where-user-mentioned-and-hasn-t-responded-after-being-mentioned/275152 "2019-03-16T00:00:32Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [March 16, 2019, 12:00am UTC](https://meta.discourse.org/t/topics-where-user-mentioned-and-hasn-t-responded-after-being-mentioned/275152/1 "2019-03-16T00:00:32Z")

</div>

I don’t know even a bit of SQL… but would it be possible to have a query that shows me topics where I’ve been mentioned… but haven’t responded _after_ being mentioned (I imagine this part is tricky, if it’s even possible)?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [March 18, 2019, 11:49am UTC](https://meta.discourse.org/t/topics-where-user-mentioned-and-hasn-t-responded-after-being-mentioned/275152/2 "2019-03-18T11:49:14Z")

</div>

### topics where user mentioned and hasn’t responded _after_ being mentioned

```sql
-- [params]
-- user_id :user

WITH mentions AS (
    SELECT target_topic_id, target_post_id, created_at
    FROM user_actions
    WHERE action_type = 7 -- mentions
    AND user_id = :user
), replies AS (
    SELECT topic_id, MAX(created_at) created_at
    FROM posts
    WHERE user_id = :user
    AND deleted_at IS NULL
    AND post_type IN (1, 4) -- regular OR whisper
    GROUP BY topic_id
)
SELECT DATE(m.created_at) mentionned_at, target_post_id post_id
FROM mentions m
LEFT JOIN replies r ON r.topic_id = m.target_topic_id
JOIN topics t ON t.id = m.target_topic_id
WHERE m.created_at > COALESCE(r.created_at, '1900-01-01')
AND t.deleted_at IS NULL
AND NOT t.archived
AND NOT t.closed
ORDER BY m.created_at DESC

```

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [August 15, 2023, 6:16pm UTC](https://meta.discourse.org/t/topics-where-user-mentioned-and-hasn-t-responded-after-being-mentioned/275152/4 "2023-08-15T18:16:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
