# Badge not working

**URL:** <https://meta.discourse.org/t/badge-not-working/39426>\
**Category:** Data & reporting\
**Tags:** sql-triggered-badge\
**Created:** [11 Febbraio 2016, 8:52pm UTC](https://meta.discourse.org/t/badge-not-working/39426 "2016-02-11T20:52:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)\
**Post date:** [11 Febbraio 2016, 9:44pm UTC](https://meta.discourse.org/t/badge-not-working/39426/2 "2016-02-11T21:44:03Z")

</div>

I don’t know if the query change in the meanwhile but the original code is this:

```plaintext
SELECT id user_id, current_timestamp granted_at
FROM users
WHERE id IN (
       SELECT p1.user_id 
       FROM post_custom_fields pc
       JOIN badge_posts p1 ON p1.id = pc.post_id
       JOIN topics t1 ON p1.topic_id = t1.id
       WHERE p1.user_id <> t1.user_id AND 
                    name = 'is_accepted_answer' AND 
            p1.user_id IN (
                   SELECT user_id 
                   FROM posts 
                   WHERE :backfill OR p1.id IN (:post_ids)
            )
        GROUP BY p1.user_id
        HAVING COUNT(*) > 9
)
```

e.g. in your code I don’t see the line “HAVING COUNT” for count the number of accepted answers

EDIT: @zee the code you paste in your post is for 1 accepted answer, not for 10

---

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