Exporting group members emails as csv

Since the email address was moved to the user_emails table, this query has changed.

The working query is now

-- [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 ue.email
FROM users u
INNER JOIN user_emails ue ON u.id = ue.user_id
INNER JOIN user_groups ug ON u.id = ug.user_id
WHERE u.id > 0
ORDER BY u.id DESC
7 Likes