# Adding users from groups to other groups in bulk

**URL:** https://meta.discourse.org/t/adding-users-from-groups-to-other-groups-in-bulk/260670
**Category:** Site Management
**Tags:** groups, data-explorer, invites
**Created:** [April 5, 2023, 3:08pm UTC](https://meta.discourse.org/t/adding-users-from-groups-to-other-groups-in-bulk/260670 "2023-04-05T15:08:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [April 5, 2023, 3:08pm UTC](https://meta.discourse.org/t/adding-users-from-groups-to-other-groups-in-bulk/260670/1 "2023-04-05T15:08:40Z")

</div>

> 🔖 This guide explains how to add existing users from one or more groups to other groups using a combination of [Data Explorer](https://meta.discourse.org/t/32566?silent=true) and [bulk invites](https://meta.discourse.org/t/sending-bulk-user-invites/16468).
> 
> 🙋 Required user level: Administrator

## Summary

This guide will show you how to:

1. Create a [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query to select users from specific groups
2. Download the query results as a CSV file
3. Use the bulk invite feature to add these users to new groups

## Requirements

- [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin installed
- Administrator access to your Discourse instance

> ⚠ Always create a backup before performing bulk operations on user groups.

## Creating the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query

1. Go to Admin → Plugins → [Data Explorer](https://meta.discourse.org/t/32566?silent=true)
2. Create a new query
3. Name your query (e.g., “Select users for group addition”)
4. Paste the following SQL code into the query input:

```sql
--[params]
-- string_list :group_name
-- string_list :new_group_names
SELECT ue.email, :new_group_names as "groups"
FROM users u
INNER JOIN group_users gu ON u.id = gu.user_id
INNER JOIN groups g on g.id = gu.group_id
INNER JOIN user_emails ue on u.id = ue.user_id
WHERE g.name IN (:group_name)
AND ue.primary = true

```

1. Click “Save Changes”
2. Reload the page if the `group_name` and `new_group_names` inputs don’t appear

Your [Data Explorer](https://meta.discourse.org/t/32566?silent=true) screen should now look like this:

 ![Data Explorer query screen](https://global.discourse-cdn.com/meta/original/4X/2/2/0/22046f94a57db74b4ccf58a51b92087529ec2913.png)

## Running the query and downloading results

1. Enter the source group name(s) in the `group_name` field
2. Enter the target group name(s) in the `new_group_names` field
3. Run the query to verify the output  
 ![Query results](https://global.discourse-cdn.com/meta/original/4X/5/0/2/5025b220383fff5d487d52339e87ad278593a4ce.png)
4. Download the results as a CSV file by clicking the ![CSV button](https://global.discourse-cdn.com/meta/original/4X/5/5/e/55e15ea16acf4a310fee9643c40ea9445958cafa.png) CSV button

> ℹ To select users from multiple groups, separate group names with a comma (,). To add users to multiple groups, separate group names with a semicolon (;).

## Bulk inviting users to new groups

1. Go to your profile’s **Invited** page (`/my/invited`)
2. Click the **Bulk Invite** button
3. Select the CSV file you downloaded  
 ![Bulk Invite screen](https://global.discourse-cdn.com/meta/original/4X/1/5/e/15efed1f0041655c731d370ea932a2eab86bffe3.png)
4. Click “Bulk Invite” to process the file  
 ![Bulk Invite confirmation](https://global.discourse-cdn.com/meta/original/4X/9/4/0/9407a645ebcc981b8aba1388a7f41075479d9e50.png)

## Verifying group additions

After the bulk invite process, check the target group(s) to ensure that the users have been added correctly.

For example, if you started with these users in the “grapes” group:

 ![Users in grapes group](https://global.discourse-cdn.com/meta/original/4X/d/e/a/dea51d6e311cd4cea7d93237d7bbf4f6b1097cfd.png)

And the “fruits” group was initially empty:

 ![Empty fruits group](https://global.discourse-cdn.com/meta/original/4X/e/e/4/ee4071b9caefbb3c749ec0e92e40374fc9acd3a3.png)

After the bulk invite, the “fruits” group should now be populated:

 ![Populated fruits group](https://global.discourse-cdn.com/meta/original/4X/c/3/d/c3df36d9dc0ff1be0766e9deba8a706f52968d81.png)

> ℹ Users added to new groups using this method will not receive any email or notification about being added to the new group(s).

## Selecting multiple groups

You can select users from multiple groups and add them to multiple groups:

 ![Multiple group selection](https://global.discourse-cdn.com/meta/original/4X/a/6/5/a6502866f1d4cc28e84dc2e891de14dc8b4b4732.png)

- To select users from multiple groups, separate group names with a comma (,): `grapes,cherries`
- To add users to multiple groups, separate group names with a semicolon (;): `fruits;vegetables`

## Additional resources

- [Sending bulk user invites](https://meta.discourse.org/t/send-bulk-user-invites/16468?silent=true)
- [Install plugins on a self-hosted site](https://meta.discourse.org/t/install-plugins-in-discourse/19157?silent=true)

> Last edited by @hugh 2024-07-16T03:08:28Z
> 
> Last checked by @hugh 2024-07-16T03:08:35Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![MentalNomad](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalnomad/32/95159_2.png) [@MentalNomad](https://meta.discourse.org/u/MentalNomad)
#### Post date: [May 20, 2023, 3:15pm UTC](https://meta.discourse.org/t/adding-users-from-groups-to-other-groups-in-bulk/260670/2 "2023-05-20T15:15:50Z")

</div>

When using this process to bulk invite pre-existing users to a new group, do the users receive an email? Do they receive any notification?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [May 22, 2023, 10:33am UTC](https://meta.discourse.org/t/adding-users-from-groups-to-other-groups-in-bulk/260670/3 "2023-05-22T10:33:19Z")

</div>

No, they will not receive an email or notification. I’ll add this information to the topic, thanks!
