# Badge preview working, badge assignment not working

**URL:** https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456
**Category:** Support
**Created:** [2016年一月25日 17:07 UTC](https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456 "2016-01-25T17:07:21Z")
**Posts on this page:** 3
**Page:** 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: [2016年一月25日 17:07 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.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [2016年一月25日 19:44 UTC](https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456/2 "2016-01-25T19:44:33Z")

</div>

Only a wild guess, does  
`CURRENT_TIMESTAMP granted_at`  
need an AS ?

EDIT  
Hmmm, Lokking at a few of the default badge queries, none of them had `CURRENT_TMESTAMP` in them.

---

<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: [2022年七月24日 09:44 UTC](https://meta.discourse.org/t/badge-preview-working-badge-assignment-not-working/38456/4 "2022-07-24T09:44:19Z")

</div>


