# See who viewed topic

**URL:** https://meta.discourse.org/t/see-who-viewed-topic/29277
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [May 26, 2015, 8:37pm UTC](https://meta.discourse.org/t/see-who-viewed-topic/29277 "2015-05-26T20:37:07Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [May 14, 2021, 10:46pm UTC](https://meta.discourse.org/t/see-who-viewed-topic/29277/11 "2021-05-14T22:46:47Z")

</div>

> [@tophee](#):
>
> Yes, you can do this with the [Data Explorer Plugin](https://meta.discourse.org/t/what-cool-data-explorer-queries-have-you-come-up-with/43516)

I’ve got a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query for this (which shows username to enable csv / groups / pms stuff):

```plaintext
-- Who viewed this topic? https://meta.discourse.org/t/see-who-viewed-topic/29277/11
-- [params]
-- int :topic_id
SELECT tu.user_id, u.username, total_msecs_viewed/1000 AS seconds_viewed
FROM topic_users tu
JOIN users u ON tu.user_id = u.id
WHERE tu.topic_id = :topic_id
    AND total_msecs_viewed > 0
GROUP BY tu.user_id, u.username, tu.total_msecs_viewed
ORDER BY tu.total_msecs_viewed desc

```

If it is okay in your context to reveal email addresses, then I suggest this one instead:

```plaintext
-- Who viewed this topic? With emails. https://meta.discourse.org/t/see-who-viewed-topic/29277/11
-- [params]
-- int :topic_id
SELECT tu.user_id, email, total_msecs_viewed/1000 AS seconds_viewed
FROM topic_users tu
JOIN user_emails ue ON tu.user_id = ue.user_id
WHERE tu.topic_id = :topic_id
    AND total_msecs_viewed > 0
GROUP BY tu.user_id, ue.email, tu.total_msecs_viewed
ORDER BY tu.total_msecs_viewed desc

```

---

_[View the full topic](https://meta.discourse.org/t/see-who-viewed-topic/29277)._
