# Data Explorer - Vote count

**URL:** https://meta.discourse.org/t/data-explorer-vote-count/266441
**Category:** Data & reporting
**Tags:** topic-voting, sql-query
**Created:** [May 28, 2023, 2:45pm UTC](https://meta.discourse.org/t/data-explorer-vote-count/266441 "2023-05-28T14:45:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tyf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tyf/32/288655_2.png) [@tyf](https://meta.discourse.org/u/tyf)
#### Post date: [May 28, 2023, 2:45pm UTC](https://meta.discourse.org/t/data-explorer-vote-count/266441/1 "2023-05-28T14:45:49Z")

</div>

Hi all!

I’m using the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin and attempting to get topics within our Feedback category - I can achieve this fine with the following query:

```plaintext
SELECT
    t.id AS topic_id,
    t.title AS topic_title,
    t.excerpt,
    t.like_count,
    ('https://our_community.com/t/' || t.slug || '/' || t.id) AS url
FROM 
    topics t
WHERE 
    t.category_id = 95
AND 
    t.created_at > NOW() - INTERVAL '2 years'
AND deleted_at IS NULL

```

What I am unsure of is how to also include the vote count associated Topic Voting plugin. Does anyone know how I might include that for each post in the query above?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [May 28, 2023, 3:11pm UTC](https://meta.discourse.org/t/data-explorer-vote-count/266441/2 "2023-05-28T15:11:14Z")

</div>

The Topic Voting tables are `discourse_voting_topic_votes` and `discourse_voting_votes`. You can include the number of votes for each topic with something like this: 👍

```sql

SELECT
    t.id AS topic_id,
    t.title AS topic_title,
    dvtv.votes_count,
    t.excerpt,
    t.like_count,
    ('https://our_community.com/t/' || t.slug || '/' || t.id) AS url
FROM 
    topics t
JOIN 
    discourse_voting_topic_vote_count dvtv ON t.id = dvtv.topic_id
WHERE 
    t.category_id = 95
AND 
    t.created_at > NOW() - INTERVAL '2 years'
AND deleted_at IS NULL

```

There are also a couple more queries you may find useful in the #data-reporting category - [Topics tagged topic-voting](https://meta.discourse.org/tags/c/data-reporting/148/topic-voting)

---

<div class="post-metadata">

### Author: ![tyf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tyf/32/288655_2.png) [@tyf](https://meta.discourse.org/u/tyf)
#### Post date: [May 28, 2023, 3:58pm UTC](https://meta.discourse.org/t/data-explorer-vote-count/266441/3 "2023-05-28T15:58:21Z")

</div>

Thanks @JammyDodger ! ❤

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [June 27, 2023, 3:58pm UTC](https://meta.discourse.org/t/data-explorer-vote-count/266441/4 "2023-06-27T15:58:24Z")

</div>

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