Need some help with a bit of Badge SQL please

I think that’s because you’re running it against people that already qualify for all four. If it was introduced ‘fresh’ I think it would automatically grant at the latest topic date as soon as a user cleared a threshold.

For a ‘legacy’ run, you may need to add a LIMIT?

Edit: Returning the first (eg) 25 eligible records per user in one query is beyond my current skills. :slightly_smiling_face:

However, depending on how many users qualify for multiple badges you could award the legacy ones manually using info from a data-explorer query? And then running the auto-badge query above should grant the right badge for the right post after those have been awarded.

Something like:

-- [params]
-- int :user_id = 1
-- int :limit = 50

SELECT bp.user_id, bp.created_at, bp.id as post_id 
FROM badge_posts bp
JOIN topics t ON t.id = bp.topic_id
WHERE bp.user_id = :user_id
AND t.category_id = 17
AND bp.post_number = 1 
AND bp.raw LIKE '%dronescene.co.uk%' 
ORDER BY bp.created_at ASC
LIMIT :limit

I apologise for any typos. :slightly_smiling_face:

(The Bronze should be do-able with the MIN version, and the Platinum with the MAX, so it’s just the 10 and 25 ones)