# Badge preview working, badge assignment not working

**URL:** <https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456>\
**Category:** Support\
**Created:** [25 Gennaio 2016, 5:07pm UTC](https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456 "2016-01-25T17:07:21Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)\
**Post date:** [25 Gennaio 2016, 5:07pm UTC](https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456/1 "2016-01-25T17:07:21Z")

</div>

Continuing the discussion from [Badges not being assigned](https://meta.discourse.org/t/badges-not-being-assigned/38220):

I originally posted the linked topic under support because I had the following badge query not working:

```sql
SELECT topics.id AS topic, posts.id AS post_id, users.id AS user_id, users.title, MAX(posts.like_count) AS like_count, CURRENT_TIMESTAMP granted_at
FROM topics
JOIN posts ON topics.id = posts.topic_id
JOIN users ON users.id = posts.user_id
WHERE posts.like_count > 0
AND users.title = 'Real Estate Agent'
AND (:backfill OR ( users.id IN (:user_ids) ))
GROUP BY topics.id, posts.id, users.id, users.title
HAVING MAX(posts.like_count) >= (SELECT MAX(p.like_count)
	FROM topics t
JOIN posts p ON t.id = p.topic_id
JOIN users u ON u.id = p.user_id
WHERE t.id = topics.id
GROUP BY u.id order by max desc limit 1)
ORDER BY MAX(posts.like_count) DESC

```

 ![](https://global.discourse-cdn.com/meta/original/3X/7/2/7256f9b27ccb6bc7a16a0ad1783d3ceb61268625.png)

The query has present for weeks and the badge has not yet been assigned. The frustrating aspect of this is that the preview badge query lists X number of users who are set to get the badge. Furthermore, on my own backend using postgres, I can see the query returns the desired results.

In the linked topic, some suggestions were to try relating the post\_id rather than the user\_id, I tried this to no avail. What are the chances that there is a bug involved? In my mind, if the Discourse is telling me that badges are to be assigned in the preview, then it should work.

---

_[View the full topic](https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456)._
