Exporting group members emails as csv

Hi @phi,

Yes, this can be done by running a query from /admin/plugins/explorer once you have discourse-data-explorer plugin installed.

Here is the query you are looking for:

-- [params]
-- group_id :group

WITH user_groups AS (
    SELECT gu.user_id
    FROM groups g
    JOIN group_users gu ON gu.group_id = g.id
    WHERE g.id = :group
    GROUP BY gu.user_id
)
SELECT u.email
FROM users u
INNER JOIN user_groups ug ON u.id = ug.user_id
WHERE u.id > 0
ORDER BY u.id DESC

The group name will be entered in group field, and once you run the query you will have the option to export the result, which will only contain user emails from the group you specified.

I hope this helps.

9 Likes