Answers.Body: <p>You've done it the correct way.  Assuming all of Craft's foreign keys and cascading deletes are all still in place, removing the user's element ID from the <code>craft_elements</code> table is the way to go and all related data will cascade delete from there.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-26T17:22:12.340Z
Answers.LastActivityDate: 2016-04-26T17:22:12.340Z
Answers.UserDisplayName: Brad Bell
Body: <p>So I have a user group containing a few thousand users and I want to remove all of those users with a SQL script.</p>
  
  <p>These users don't have access to the control panel and so don't have any Entries authored by them.</p>
  
  <p>At the moment I have this:</p>
  
  <pre><code>DELETE FROM elements WHERE id IN (SELECT userId FROM usergroups_users WHERE `groupId` = 5);
  </code></pre>
  
  <p>It looks like this removes related entries from the <code>users</code>, <code>usergroups_users</code> and <code>content</code> tables by virtue of the foreign key/cascade constraints. </p>
  
  <p>Is there anything else I need to clean up?</p>
  
Tags: <users><permissions><mysql>
Title: What SQL query can I run to remove all users assigned to a particular group?
ThreadText: # What SQL query can I run to remove all users assigned to a particular group?
  
  (Asked by: username_0 on 2016-04-26)
  
  So I have a user group containing a few thousand users and I want to remove all of those users with a SQL script.
  
  These users don't have access to the control panel and so don't have any Entries authored by them.
  
  At the moment I have this:
  
  ```
  DELETE FROM elements WHERE id IN (SELECT userId FROM usergroups_users WHERE `groupId` = 5);
  
  ```
  
  It looks like this removes related entries from the `users`, `usergroups_users` and `content` tables by virtue of the foreign key/cascade constraints.
  
  Is there anything else I need to clean up?
  
  **Tags:** users, permissions, mysql
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-04-26. Score: 2 | Accepted answer
  
  You've done it the correct way. Assuming all of Craft's foreign keys and cascading deletes are all still in place, removing the user's element ID from the `craft_elements` table is the way to go and all related data will cascade delete from there.
  
  
  ---
  
  