# איך לסנן נושאים לפי קבוצת משתמשים

**URL:** <https://meta.discourse.org/t/how-to-filter-topics-by-user-group/266582>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [30 במאי,‏ 2023,‏ 9:30am UTC](https://meta.discourse.org/t/how-to-filter-topics-by-user-group/266582 "2023-05-30T09:30:42Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [1 ביוני,‏ 2023,‏ 8:49am UTC](https://meta.discourse.org/t/how-to-filter-topics-by-user-group/266582/5 "2023-06-01T08:49:59Z")

</div>

No worries. I think the edited one works. 👍 🙂 Just to note, it can also be useful to put a few extras in to filter deleted topics/posts, PMs, and Whispers/Small Action posts too. Something like:

```sql
SELECT 
    t.id AS topic_id, 
    t.title AS topic_title, 
    (SELECT user_id FROM posts WHERE topic_id = t.id ORDER BY created_at DESC LIMIT 1) AS last_post_user_id
FROM topics t
JOIN posts p ON p.topic_id = t.id
JOIN group_users gu ON gu.user_id = p.user_id
JOIN groups g ON g.id = gu.group_id
WHERE g.name = 'clients'
AND t.deleted_at ISNULL
AND p.deleted_at ISNULL
AND p.post_type = 1
AND t.archetype = 'regular'
GROUP BY t.id
HAVING MAX(p.user_id) = last_post_user_id
ORDER BY MAX(p.created_at) DESC

```

Though I don’t think this would catch any topic where the OP replied again (eg. to say ‘thanks’ etc), so it may need a different method depending on what you’re after @kenjdarhan. Would it be specifically client created topics which had received a reply from a team member and were also unsolved? Something like that?

---

_[View the full topic](https://meta.discourse.org/t/how-to-filter-topics-by-user-group/266582)._
