Quote from: Konsum at Mar 29, 2007, 09:16 AM
I want to add all users with an id higher than 3 into user group 2. Could you help me to correct the code above?
(FYI, I think I had my table names mixed up...No worries!)
Run the following SQL:
select * from modx_webgroup_names
Please confirm that where "id = 2" is the correct Web Group name you want them moved to.
Once you’re sure of the proper web_group id, then you would likely need two queries: an
UPDATE statement for any users
already assigned to a webgroup and then an
INSERT statement for those that are have not. I would recommend running both queries (in order).
First:
UPDATE desired web user’s assigned webgroup id:
[This will update any webuser > 3 record in modx_web_groups with webgroup id: 2]
update modx_web_groups wg
inner join modx_web_users wu on wg.webuser = wu.id and wu.id > 3
set wg.webgroup = '2'
Last:
INSERT desired web users into assigned webgroup id:
[This will add any webuser > 3 not already in modx_web_groups into modx_web_groups with webgroup id: 2]
insert into modx_web_groups (webgroup,webuser)
select '2' as webgroup, wu.id as webuser
from modx_web_users wu
left join modx_web_groups wg on wg.webuser = wu.id
where wg.webuser is null and wu.id > 3
Let me know if this helps. Enjoy!