# Data discrepancy in user post counts

**URL:** https://meta.discourse.org/t/data-discrepancy-in-user-post-counts/177214
**Category:** Data & reporting
**Tags:** sql-query
**Created:** [January 25, 2021, 8:14pm UTC](https://meta.discourse.org/t/data-discrepancy-in-user-post-counts/177214 "2021-01-25T20:14:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hollyw](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@hollyw](https://meta.discourse.org/u/hollyw)
#### Post date: [January 25, 2021, 8:14pm UTC](https://meta.discourse.org/t/data-discrepancy-in-user-post-counts/177214/1 "2021-01-25T20:14:16Z")

</div>

I’m trying to figure out a potential data discrepancy I’m seeing. I’ve been doing some queries with the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin to get stats on our most-frequently posting users. One query I used was the following:

```plaintext
select u.username, us.post_count
from users u
join user_stats us
on u.id = us.user_id
order by us.post_count desc

```

This was returning, say, 100 posts for a particular user. Then I decided to redo the query a little differently:

```plaintext
select u.username, count(distinct p.id)
from users u
join posts p
on u.id = p.user_id
group by u.username
order by count(distinct p.id) desc

```

This query for that particular user returned 135 posts. And this seems to be the correct number, since it’s actually counting every single post from the posts table, as opposed to relying on the `post_count` field from `user_stats`.

So I’m trying to understand why there would be a discrepancy here. This is for a non-admin, non-mod user, so they don’t have a bunch of admin actions that are appearing as posts. Any ideas why this might be happening?

---

<div class="post-metadata">

### Author: ![JusticeUK](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@JusticeUK](https://meta.discourse.org/u/JusticeUK)
#### Post date: [January 26, 2021, 12:02am UTC](https://meta.discourse.org/t/data-discrepancy-in-user-post-counts/177214/2 "2021-01-26T00:02:13Z")

</div>

Hi Holly, the table posts will also include private messages and deleted posts. Maybe user\_stats.post\_count only includes undeleted posts, and not private messages and deleted posts? Someone with more knowledge can hopefully answer.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [January 26, 2021, 2:27am UTC](https://meta.discourse.org/t/data-discrepancy-in-user-post-counts/177214/3 "2021-01-26T02:27:44Z")

</div>

Yup, that’s exactly right @JusticeUK

---

<div class="post-metadata">

### Author: ![hollyw](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@hollyw](https://meta.discourse.org/u/hollyw)
#### Post date: [January 26, 2021, 2:41pm UTC](https://meta.discourse.org/t/data-discrepancy-in-user-post-counts/177214/4 "2021-01-26T14:41:12Z")

</div>

Thanks for the info. However, this user has no deleted posts (I double checked their profile and added a `p.deleted_at is null` to my above query and am still seeing the same numbers. Our forum also has PM’s disabled, so I don’t think those would be messing with the numbers.

When looking at this user’s posts, they are all `post_type = 1`. I don’t know what exactly a `post_type` of 1 means yet, but all of his just seem to be normal posts.
