Linking badge sql to a topic id?

I have this SQL in the settings of a badge and it awards a badge to anyone that gets added to the beta-testers group:

SELECT u.id AS user_id, CURRENT_TIMESTAMP AS granted_at
FROM users u
INNER JOIN group_users gu ON gu.user_id = u.id
INNER JOIN groups g ON g.id = gu.group_id
WHERE g.name = 'beta-testers'

Can I modify that to also link the badge to a specific topic ID? :thinking:

I think you can:

SELECT
  u.id AS user_id,
  CURRENT_TIMESTAMP AS granted_at,
  (SELECT id FROM posts WHERE topic_id = YOUR_TOPIC_ID AND post_number = 1) AS post_id
FROM users u
INNER JOIN group_users gu ON gu.user_id = u.id
INNER JOIN groups g ON g.id = gu.group_id
WHERE g.name = 'beta-testers'

Replace YOUR_TOPIC_ID

And it has to have Query targets posts ticked I think.

Lmk if that works.

Thanks @chapoi, I’ve applied that change.

If I click the [Preview granted badges] button it’s looking good, and it’s showing me the topic it will tie the badge to.

I’ll reply back in the next 24hrs when they’ve been issued :crossed_fingers:t2: