# É possível ver os tópicos que um usuário visualizou?

**URL:** https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [20 Junho , 2020 04:08 UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413 "2020-06-20T04:08:45Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![ditatompel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ditatompel/32/141759_2.png) [@ditatompel](https://meta.discourse.org/u/ditatompel)
#### Post date: [20 Junho , 2020 15:43 UTC](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413/2 "2020-06-20T15:43:35Z")

</div>

Talvez algo como:

# Quem (usuário logado) visualiza um tópico específico

```sql
-- [params]
-- int :topic_id = 1

SELECT
    title,
    viewed_at,
    tv.user_id
FROM topics t
LEFT JOIN topic_views tv
    ON t.id = tv.topic_id
WHERE category_id IS NOT NULL
    AND tv.user_id IS NOT NULL
    AND t.id = :topic_id
ORDER BY viewed_at DESC
LIMIT 1000

```

# Últimas 100 visualizações de tópicos por usuário

```sql
-- [params]
-- int :user_id = 1

SELECT
    tv.user_id,
    title,
    viewed_at,
    views,
    t.user_id
FROM topics t
LEFT JOIN topic_views tv
    ON t.id = tv.topic_id
WHERE category_id IS NOT NULL
    AND tv.user_id = :user_id
ORDER BY viewed_at DESC
LIMIT 100

```

---

_[View the full topic](https://meta.discourse.org/t/is-it-possible-to-see-the-topics-a-user-has-viewed/155413)._
