# Data explorer query for events?

**URL:** https://meta.discourse.org/t/data-explorer-query-for-events/272536
**Category:** Data & reporting
**Tags:** events, sql-query
**Created:** [July 23, 2023, 5:05am UTC](https://meta.discourse.org/t/data-explorer-query-for-events/272536 "2023-07-23T05:05:14Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)
#### Post date: [July 23, 2023, 5:05am UTC](https://meta.discourse.org/t/data-explorer-query-for-events/272536/1 "2023-07-23T05:05:15Z")

</div>

I have tried querying something as simple as this, to start:

```plaintext
SELECT *
FROM discourse_post_event_invitees
WHERE post_id = :post_id

```

Unfortunately I’m getting 0 results back for a post that I know has 15 users marked as Going. Any ideas?

---

<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: [July 23, 2023, 1:18pm UTC](https://meta.discourse.org/t/data-explorer-query-for-events/272536/2 "2023-07-23T13:18:09Z")

</div>

That should work. Are you grabbing the right post id from the json?

I think you could link it up to the posts table and use a topic id, which may be less faff than finding the post id. Something like:

```sql
-- [params]
-- topic_id :topic_id

SELECT ei.user_id, ei.status
FROM discourse_post_event_invitees ei
JOIN posts p ON p.id = ei.post_id 
WHERE p.topic_id = :topic_id

```

---

<div class="post-metadata">

### Author: ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)
#### Post date: [July 23, 2023, 1:22pm UTC](https://meta.discourse.org/t/data-explorer-query-for-events/272536/3 "2023-07-23T13:22:20Z")

</div>

Okay, getting closer. That returns everyone who is going or interested, how do you differentiate?

---

<div class="post-metadata">

### Author: ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)
#### Post date: [July 23, 2023, 1:43pm UTC](https://meta.discourse.org/t/data-explorer-query-for-events/272536/4 "2023-07-23T13:43:43Z")

</div>

Ah, okay, the name of the key “status” confused me a bit. I was thinking that was some sort of status of the event.

`status = 0` = Going  
`status = 1` = Interested  
`status = 2` = Not Going

---

<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: [July 23, 2023, 6:42pm UTC](https://meta.discourse.org/t/data-explorer-query-for-events/272536/5 "2023-07-23T18:42:34Z")

</div>

You can make it a bit easier to read without remembering the codes too if you add in a little something like this:

```sql

-- [params]
-- topic_id :topic_id

SELECT ei.user_id,
      CASE 
       WHEN ei.status = 0 THEN 'Going' 
       WHEN ei.status = 1 THEN 'Interested'
       WHEN ei.status = 2 THEN 'Not going' 
        END AS "Going?"
FROM discourse_post_event_invitees ei
JOIN posts p ON p.id = ei.post_id 
WHERE p.topic_id = :topic_id
ORDER BY ei.status

```
