# Joining classification\_results table to other tables support request

**URL:** https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640
**Category:** Data & reporting
**Tags:** ai, sql-query, ai-sentiment
**Created:** [June 25, 2025, 12:59pm UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640 "2025-06-25T12:59:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SStrong](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@SStrong](https://meta.discourse.org/u/SStrong)
#### Post date: [June 25, 2025, 12:59pm UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/1 "2025-06-25T12:59:35Z")

</div>

I have a request to create using [data explorer](https://meta.discourse.org/t/32566?silent=true) dashboards at Category level with certain key metrics that will be automated via automation every month, going to Category moderators so that they can be aware of performance, make business decisions off the back of it.

Sentiment analysis - this has been requested at Category level. I have looked in the classification\_results table to understand how to join this, however there’s limited columns and just one called target\_id but no idea what that refers to and I only see it in ai related tables

Please support

---

<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: [June 25, 2025, 4:33pm UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/2 "2025-06-25T16:33:07Z")

</div>

> [@SStrong](#):
>
> one called target\_id but no idea what that refers to

I think this is dependant on the `target_type` column. For instance, if it’s got a target\_type of ‘post’ then the target\_id is a post\_id

---

<div class="post-metadata">

### Author: ![Michael12](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michael12/32/507366_2.png) [@Michael12](https://meta.discourse.org/u/Michael12)
#### Post date: [June 26, 2025, 5:00am UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/3 "2025-06-26T05:00:47Z")

</div>

Thanks, that helps a lot.

So just to check—if `target_type` is ‘post’, then I should join `classification_results.target_id` to `posts.id`, right?

And if the `target_type` is something else, like ‘comment’, then I’d join it to the `comments` table instead? Just want to make sure I’m joining to the right table based on the type.

---

<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: [June 26, 2025, 7:13am UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/4 "2025-06-26T07:13:46Z")

</div>

> [@Michael12](#):
>
> And if the `target_type` is something else, like ‘comment’, then I’d join it to the `comments` table instead?

I’m not sure comments are processed by AI sentiment. 🤔 Is this a `target_type` you’re seeing in your data?

I think it may currently be post only, but with a format that allows it to be expanded to other entities in the future. My data set is limited though, so if you could run this query and see what different types you have that would be very useful:

```sql
SELECT target_type
FROM classification_results
GROUP BY 1 

```

---

<div class="post-metadata">

### Author: ![SStrong](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@SStrong](https://meta.discourse.org/u/SStrong)
#### Post date: [June 26, 2025, 8:22am UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/5 "2025-06-26T08:22:20Z")

</div>

> [@JammyDodger](#):
>
> ```plaintext
> SELECT target_type
> FROM classification_results
> GROUP BY 1 
> 
> ```

I can only see post as a target\_type. Am I correct in thinking that a post is a multiple of types in it’s on right as well. For example, one topic can have 10 posts in total. So does that mean that the sentiment analysis in this case would be applied 10 times, once to each post of a topic? Meaning if the ask was to create a dashboard which shows the sentiment score per topic by category, another step would be to then understand how many of the posts of a topic even have had sentiment analysis applied, then create an average?

---

<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: [June 26, 2025, 9:00am UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/6 "2025-06-26T09:00:04Z")

</div>

The sentiment analysis is applied at the post level, so each post would have its own record in the `classification_results` table. Each post would also have a separate record for every model applied to it as well, so depending on which results you’re interested in you’d want to filter out those specific ones for that model.

> [@SStrong](#):
>
> Meaning if the ask was to create a dashboard which shows the sentiment score per topic by category, another step would be to then understand how many of the posts of a topic even have had sentiment analysis applied, then create an average?

I think this may depend on which results you’re interested in. The positive/negative sentiments may lend themselves better to that concept. The emotion ones might be better laid out as separate columns per topic.

But you may be able to get some ideas from the existing ones:

> [@Dashboard Report - Overall Sentiment](https://meta.discourse.org/t/dashboard-report-overall-sentiment/295428):
>
> This is an SQL version of the Dashboard Report for Overall Sentiment. discourse This report requires the [Discourse AI](https://meta.discourse.org/t/discourse-ai/259214) plugin and [Sentiment Analysis](https://meta.discourse.org/t/enable-sentiment-analysis/259599) to be enabled. This dashboard report compares the number of posts classified either positive or negative with the “Sentiment” AI, over a specified period. By leveraging sentiment analysis, the report categorizes posts as either positive or negative based on a defined threshold, which can be adjusted. This categorization is then used to calcula…

> [@Dashboard Report - Post Emotion](https://meta.discourse.org/t/dashboard-report-post-emotion/295553):
>
> This is an SQL version of the Dashboard Report for Post Emotion. discourse This report requires the [Discourse AI](https://meta.discourse.org/t/discourse-ai/259214) plugin and [Sentiment Analysis](https://meta.discourse.org/t/enable-sentiment-analysis/259599) to be enabled. This dashboard report shows the number of posts classified with one of following emotions, group by poster trust level, within a specified date range: Sadness Surprise Fear Anger Joy Disgust Admiration Amusement Annoyance Approval Caring Confusion Curiosity Desire Disappointment Disapproval Embarrassment Excitement Gratitude Grief L…

---

<div class="post-metadata">

### Author: ![SStrong](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@SStrong](https://meta.discourse.org/u/SStrong)
#### Post date: [July 3, 2025, 9:28am UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/7 "2025-07-03T09:28:00Z")

</div>

Overall sentiment code is not working, I get no results at all but the fronn=t end sentiment analysis is showing for users

---

<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: [July 3, 2025, 6:48pm UTC](https://meta.discourse.org/t/joining-classification-results-table-to-other-tables-support-request/371640/8 "2025-07-03T18:48:17Z")

</div>

Hmm. 🤔 I’ve just given it a test and it works for me.

Maybe a little basic, but just to check, did you adjust the date range parameters to something more recent than the default ones?
