I don't know how to do it in SQL, but you could use this script:
PHP Code:
<?php
require_once("global.php");
// remove this group from users who have this group as a membergroup (secondary group)
$usergroupid = X; // change to group id to remove
$casesqlm = $casesqli = '';
$updateusersm = $updateusersi = array();
echo ("Removing users from secondary group id=" . $usergroupid . "<BR/><BR/>\r\n");
flush();
$users = $db->query_read("
SELECT userid, username, membergroupids, infractiongroupids
FROM " . TABLE_PREFIX . "user
WHERE FIND_IN_SET('" . $usergroupid . "', membergroupids)
");
if ($db->num_rows($users))
{
while($user = $db->fetch_array($users))
{
if (!empty($user['membergroupids']))
{
$membergroups = fetch_membergroupids_array($user, false);
foreach($membergroups AS $key => $val)
{
if ($val == $usergroupid)
{
unset($membergroups["$key"]);
}
}
$user['membergroupids'] = implode(',', $membergroups);
$casesqlm .= "WHEN $user[userid] THEN '$user[membergroupids]' ";
$updateusersm[] = $user['userid'];
}
}
// do big update to get rid of this usergroup from matched members' membergroupids
if (!empty($casesqlm))
{
$db->query_write("
UPDATE " . TABLE_PREFIX . "user SET
membergroupids = CASE userid
$casesqlm
ELSE '' END
WHERE userid IN(" . implode(',', $updateusersm) . ")
");
}
}
die("Done.");
First you probably want to make a backup of your database, or at least the user table. And you might want to close your forum while you run this.
Next, create a new php file (like maybe removegroup.php) and put in the above code. Then change this line
PHP Code:
$usergroupid = X; // change to group id to remove
to change X to the group id your want to remove. Then run the script (go to it with your browser).
When you're done you'll probably want to remove it.
BTW, this code comes from admincp/usergroup.php where it's used to remove users from a group when the group is being deleted.