# User(s) in a Group who Haven't Voted

**URL:** https://meta.discourse.org/t/user-s-in-a-group-who-havent-voted/82918
**Category:** Data & reporting
**Tags:** topic-voting, sql-query
**Created:** [13.Март.2018 17:50:24 UTC](https://meta.discourse.org/t/user-s-in-a-group-who-havent-voted/82918 "2018-03-13T17:50:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [13.Март.2018 17:50:24 UTC](https://meta.discourse.org/t/user-s-in-a-group-who-havent-voted/82918/1 "2018-03-13T17:50:24Z")

</div>

### User(s) in a Group who Haven’t Voted

This will give you the users who belong to a named group who have not voted in any open topics. You’ll need to supply the value for the group\_name parameter.

```sql
-- [params]
-- string :group_name

WITH voters AS (
SELECT user_id AS voter_id
FROM topic_voting_votes
WHERE archive = FALSE
)

SELECT u.id AS user_id
FROM users u 
JOIN group_users gu ON gu.user_id = u.id 
JOIN groups g ON g.id = gu.group_id
WHERE LOWER(g.name) LIKE LOWER(:group_name)
AND u.id NOT IN (SELECT voter_id FROM voters)

```

This will give you the users who belong to a named group who have not voted on a given topic. You’ll need to supply the group\_name and topic\_id:

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

WITH voters AS (
SELECT user_id AS voter_id
FROM topic_voting_votes tvv
WHERE tvv.topic_id = :topic_id
)

SELECT u.id AS user_id
FROM users u
JOIN group_users gu ON gu.user_id = u.id
JOIN groups g ON g.id = gu.group_id
WHERE LOWER(g.name) LIKE LOWER(:group_name)
AND u.id NOT IN (SELECT voter_id FROM voters)

```
