# 배지 SQL을 토픽 ID에 연결하는 방법?

**URL:** https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943
**Category:** Support
**Tags:** sql-triggered-badge
**Created:** [6월 10, 2026, 12:54오후 UTC](https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943 "2026-06-10T12:54:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [6월 10, 2026, 12:54오후 UTC](https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943/1 "2026-06-10T12:54:20Z")

</div>

배지 설정에 이 SQL을 사용했는데, `beta-testers` 그룹에 추가된 모든 사용자에게 배지를 부여합니다:

```plaintext
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'

```

이를 수정해서 배지를 특정 토픽 ID와도 연결할 수 있을까요? 🤔

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [6월 10, 2026, 1:24오후 UTC](https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943/2 "2026-06-10T13:24:52Z")

</div>

아래처럼 하면 될 것 같아요:

```plaintext
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'

```

`YOUR_TOPIC_ID` 부분을 교체해 주세요.

그리고 `Query targets posts` 옵션이 체크되어 있어야 할 것 같아요.

동작하는지 확인해 보고 알려주세요.

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [6월 10, 2026, 1:53오후 UTC](https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943/3 "2026-06-10T13:53:31Z")

</div>

@chapoi 감사합니다. 해당 변경 사항을 적용했습니다.

`[Preview granted badges]` 버튼을 클릭하면 잘 표시되고 있으며, 배지가 연결될 토픽도 확인됩니다.

배지가 발급되면 24시간 이내에 다시 답변드리겠습니다 🤞🏻

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [6월 11, 2026, 12:48오후 UTC](https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943/4 "2026-06-11T12:48:49Z")

</div>

@chapoi 정말 잘 작동했어요, 다시 한번 감사합니다 😃

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [7월 11, 2026, 12:49오후 UTC](https://meta.discourse.org/t/linking-badge-sql-to-a-topic-id/404943/5 "2026-07-11T12:49:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
